So I'm trying to do a loading scene where it has hints towards the game at the bottom and I have a randomizer script
local num = math.random(1,3) local BrickEvent = game.ReplicatedStorage.Events.Gui BrickEvent.OnClientEvent:Connect(function(plr) if num == 1 then print("you got Critical Hit Fact") script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=true elseif num == 2 then print("you got Stamina Fact") script.Parent.ScreenGui.Frame.HintStamina.Visible=true elseif num == 3 then print("you got Jump Attack Fact") script.Parent.ScreenGui.Frame.HintJump.Visible=true wait(12) script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=false script.Parent.ScreenGui.Frame.HintStamina.Visible=false script.Parent.ScreenGui.Frame.HintJump.Visible=false end end)
but after it picks a random one at the beginning every time I click its the first one over and over again it doesn't ever randomize after the first click help?
The reason this doesn't work is because the random number was already chosen before the function. So your num is before the function so that means its randomized and then every time your function runs its always one number because the random number was before the function. To fix this, just put the local variable INSIDE the function, so each time the function runs, a random number is chosen, not the script you have which already has a chosen number before everything, and it stays like that forever.
Fixed Code:
-- move the local num inside the function local BrickEvent = game.ReplicatedStorage.Events.Gui BrickEvent.OnClientEvent:Connect(function(plr) local num = math.random(1,3) -- random number inside function so that every time function runs there's random number if num == 1 then print("you got Critical Hit Fact") script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=true elseif num == 2 then print("you got Stamina Fact") script.Parent.ScreenGui.Frame.HintStamina.Visible=true elseif num == 3 then print("you got Jump Attack Fact") script.Parent.ScreenGui.Frame.HintJump.Visible=true wait(12) script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=false script.Parent.ScreenGui.Frame.HintStamina.Visible=false script.Parent.ScreenGui.Frame.HintJump.Visible=false end end)