Ah, I see the issue! The error is because of a missing comma in the CONFIG table. Let me fix that and provide a cleaner version of the script. Here's the corrected code:
-------------------------------------------------------------------
-- Apple Spawner v1
-- Put this Script in ServerScriptService
-------------------------------------------------------------------
--// Services
local TweenService = game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
--// Config -------------------------------------------------------
local CONFIG = {
AppleName = "Apple", -- name of the model/part in ServerStorage
StartPartName = "StartPart", -- name of the starting marker in workspace
EndPartName = "EndPart", -- name of the destination marker in workspace
TravelTime = 5, -- seconds it takes to move to EndPart
RespawnDelay = 3, -- seconds to wait before the next spawn
InitialOrientation = CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)) -- X, Y, Z in degrees
}
-------------------------------------------------------------------
--// References
local appleTemplate = ServerStorage:WaitForChild(CONFIG.AppleName)
local startPart = workspace:WaitForChild(CONFIG.StartPartName)
local endPart = workspace:WaitForChild(CONFIG.EndPartName)
--// Helper: puts a model/part at a CFrame ------------------------
local function setCFrame(object, cf)
if object:IsA("Model") then
if not object.PrimaryPart then
warn(object.Name .. " has no PrimaryPart!")
return
end
object:SetPrimaryPartCFrame(cf)
else
object.CFrame = cf
end
end
--// Main loop ----------------------------------------------------
while true do
----------------------------------------------------------------
-- 1) Spawn
----------------------------------------------------------------
local apple = appleTemplate:Clone()
apple.Parent = workspace
-- Set initial CFrame with optional orientation adjustment
local initialCFrame = startPart.CFrame * CONFIG.InitialOrientation
setCFrame(apple, initialCFrame)
----------------------------------------------------------------
-- 2) Move (tween) to EndPart
----------------------------------------------------------------
local tweenInfo = TweenInfo.new(
CONFIG.TravelTime,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut
)
local tweenTarget
if apple:IsA("Model") then
tweenTarget = apple.PrimaryPart
else
tweenTarget = apple
end
local tween = TweenService:Create(
tweenTarget,
tweenInfo,
{CFrame = endPart.CFrame}
)
tween:Play()
tween.Completed:Wait()
----------------------------------------------------------------
-- 3) Destroy & wait
----------------------------------------------------------------
apple:Destroy()
wait(CONFIG.RespawnDelay)
end
The error occurred because I had a comma after the last element in the CONFIG table. In Lua, you should not have a comma after the last element in a table. I've removed that comma and the script should now work without errors.
If you want to rotate the Apple "up" as it spawns, you can adjust the InitialOrientation in the CONFIG table. For example, to rotate it 90 degrees around the X-axis (so it's "upright"), you can set:
InitialOrientation = CFrame.Angles(math.rad(90), math.rad(0), math.rad(0))
This will make the Apple spawn with its top pointing "up" relative to the world's coordinates, assuming the StartPart is oriented normally.