Hi there! This is my first time making a math.random script, I have it working so that it chooses a random number upon clicking a GUI button. It IS working, but I also have it set to print when it chooses a random number - and for some reason, even before I click the button, it is choosing numbers and I can see it printing numbers in the output. It's kind of acting like it's on a "while true do" script instead of on a function onClick() . Is this normal?
local plr = game.Players.LocalPlayer
local tools = plr.Backpack
local SparklingSunBeam = game.ServerStorage.foods.unprepared.Milk
Player=script.Parent.Parent.Parent.Parent.Parent
function onClick()
local randomkey = math.random(1,2)
if randomkey == 1 then
print(1)
SparklingSunBeam=game.ServerStorage.foods.unprepared.Milk:clone()
SparklingSunBeam.Parent=Player.Backpack
end
if randomkey == 2 then
print(2)
SparklingSunBeam=game.ServerStorage.foods.unprepared.Spoon:clone()
SparklingSunBeam.Parent=Player.Backpack
end
end
script.Parent.MouseButton1Down:connect(onClick)
I hope that explanation makes sense. It's only supposed to choose a random number upon the function onClick(), but when I press play I see it choosing random numbers before I click the button.
Perhaps this is how the math.random just works, I know in other games (not roblox) that have "random" spells it's constantly going on in the background even before you click it.
Is this normal or did I do something wrong?
