Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesnt this script print a random value?

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

4 comments

0

The numerical inputs within the math.radom function cannot be used for it's arethmetic operations

0

Is there a way I could rewrite the code, i have tried putting the actual numbers in instead of XPosition and SecondValueX, however it still returns an error.

0

Here´s the error : Workspace.TrashSpawn:13: bad argument #2 to 'random' (interval is empty)

0

I can't follow why didn't he just put numbers would be easier to use google to subtract that.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.