Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Cube Doesnt Wanna Go To Random Location Help?

Asked by 3 years ago

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

Log in to vote
0
Answered by
5o7h 15
3 years ago

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)
Ad
Log in to vote
0
Answered by
Echtic 128
3 years ago
Edited 3 years ago

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.

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

Answer this question