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

[FIXED BY ME] I made a script for a randomly generated sign, not switching text. Why?

Asked by 4 years ago
Edited 4 years ago

This question has been solved by the original poster.

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.

01local text = script.Parent.SurfaceGui.TextLabel
02 
03local number = math.random(3)
04i = 10
05 
06while i == 10 do
07    if number == 3 then
08        text.Text = "Now turn back :)"
09        wait(10)
10        text.Text = ""
11        local number = math.random(3)
12        print(number)
13    end
14 
15    if number == 2 then
View all 30 lines...

Thank you for helping :)

Not gonna lie, I did a dumb. If anyone is curious, on the lines where I 'Redifined" number I typed 'local' before, like this

1local 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

01local text = script.Parent.SurfaceGui.TextLabel
02 
03local number = math.random(3)
04i = 10
05 
06while i == 10 do
07    if number == 3 then
08        text.Text = "Now turn back :)"
09        wait(10)
10        text.Text = ""
11        number = math.random(3)
12        print(number)
13    end
14 
15    if number == 2 then
View all 30 lines...

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Be sure to check out the Roblox API Documentation as well for additional reference.

0
As you answered this, I fixed the script. Sorry lol! pokemine1o9 44 — 4y
Ad

Answer this question