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

Cube Doesnt Wanna Go To Random Location Help?

i Was Trying To Make A Pile Of Sand Go To A Different Place Every Time You Press In It But It Doesnt Work It Just Sends Me This Error:

Players.RacerDreng.Backpack.MetalDetector.LocalScript:7: invalid argument #2 to 'random' (interval is empty)

And This Is My Script:

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
	if mouse.Target.Name == "Treasure" then
		local Z = math.random(22.5,45.5)
		print(Z)
		local X = math.random(74.5,24.5)
		print(X)
		mouse.Target.Position = Vector3.new(X,mouse.Target.Position.Y,Z)
		print(mouse.Target.Position)
	end
end)

it is in a local script BTW

Please Help.

3 answers

✓ Accepted answer

Not sure but, I think that math.random goes from least to greatest so for line 7 do

local X = math.random(24.5,74.5)

I am not 100% sure this is the problem, but it's worth a try. Try changing the interval to integers for example:

local Z = math.random(22,45) cause i believe the random function doesn't work unless the two numbers in the interval are both integers.

math.random() will only accept integers as parameters, meaning floats will not work. You can, however, divide the random integer to obtain a desired float. For example, for 0.1-1.0:

local num = math.random(1, 10) / 10

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