So, I'm making a sign that every 1 minutes (I know, my script says 10 seconds, that's just for making testing easier) It will change text. The first time the script runs, it randomly picks a line of text, Which works. But the second time it runs, it prints the randomly generated number correctly but the text on the sign does not change. Heres my code.
local text = script.Parent.SurfaceGui.TextLabel local number = math.random(3) i = 10 while i == 10 do if number == 3 then text.Text = "Now turn back :)" wait(10) text.Text = "" local number = math.random(3) print(number) end if number == 2 then text.Text = "What are you gonna do now?" wait(10) text.Text = "" local number = math.random(3) print(number) end if number == 1 then text.Text = "There's nothing here. Lol." wait(10) text.Text = "" local number = math.random(3) print(number) end end
Not gonna lie, I did a dumb. If anyone is curious, on the lines where I 'Redifined" number I typed 'local' before, like this
local number = math.random(3)
this was creating a new variable, I had to remove the local to fix the script, so now the script looks like this
local text = script.Parent.SurfaceGui.TextLabel local number = math.random(3) i = 10 while i == 10 do if number == 3 then text.Text = "Now turn back :)" wait(10) text.Text = "" number = math.random(3) print(number) end if number == 2 then text.Text = "What are you gonna do now?" wait(10) text.Text = "" number = math.random(3) print(number) end if number == 1 then text.Text = "There's nothing here. Lol." wait(10) text.Text = "" number = math.random(3) print(number) end end
Howdy!
Your number value isn't changing as it's predefined outside of the loop. If you move the variable inside the loop, it'll continuously reroll the number at random. You also won't need the number reroll inside the three functions.
If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.