I have recently been making where I need trash to appear in a specific area, however my script doesnt work. The output says that there is a error in line 13.
local TrashSpawnHere = game.Workspace.TrashSpawnHere local function CreateTrash() local Trash = game.Workspace.TrashPart local TrashClone = Trash:Clone() TrashClone.Parent = game.Workspace local TrashSpawnHereSizeX = TrashSpawnHere.Size.X local XPostion = TrashSpawnHere.CFrame.X print(XPostion) local SecondValueX = XPostion - TrashSpawnHereSizeX print(SecondValueX) local XPositionRandom = math.random(XPostion,SecondValueX) local TrashSpawnHereSizeZ = TrashSpawnHere.Size.Z local ZPosition = TrashSpawnHere.CFrame.Z print(ZPosition) local SecondValueZ = ZPosition - TrashSpawnHere print(SecondValueZ) local ZPositionRandom = math.random(ZPosition,SecondValueZ) end while true do CreateTrash() wait(2) end
i BELieve the issue is because SecondValueZ is learned after you want it to print, the variable is placed after it which is likely the issue.