Hello there, I tried to make a TextLabel where the text constantly changes it's number with the math.random script, which I obviously used the while loop to make it constantly change without stopping, however it doesn't seem to work, the TextLabel's Text isn't changing at all, how do I fix it?
SCRIPT:
01 | local user = game:GetService( "Players" ).LocalPlayer |
02 | local indiUI = user.PlayerGui.Roll.TextLabel |
03 | local what = game.Workspace.lobbySpawn |
04 |
05 | what.Touched:Connect( function () |
06 | while true do |
07 | wait() |
08 | local numbers = math.random( 1 , 6 ) |
09 | if numbers = = 1 then |
10 | indiUI.Text = "1" |
11 | elseif numbers = = 2 then |
12 | indiUI.Text = "2" |
13 | elseif numbers = = 3 then |
14 | indiUI.Text = "3" |
15 | elseif numbers = = 4 then |
I hope this works for you.
01 | local user = game:GetService( "Players" ).LocalPlayer |
02 | local indiUI = user.PlayerGui.Roll.TextLabel |
03 | local what = game.Workspace.lobbySpawn |
04 |
05 | local timeToWait = 0.01 |
06 |
07 | while true do -- Looping forever (true will always equal true) |
08 | random = tostring (math.random( 1 , 6 )) -- creating a variable called random. I get a random number from one to six then convert it to a string |
09 | indiUI.Text = random -- Then set the text of indiUI to it |
10 | wait(timeToWait) -- Then wait |
11 | end |
01 | local user = game:GetService( "Players" ).LocalPlayer |
02 | local indiUI = user.PlayerGui.Roll.TextLabel |
03 | local what = game.Workspace.lobbySpawn |
04 |
05 | local waitTime = 0 |
06 |
07 | while true do |
08 | local random = tostring (Random.new():NextInteger( 1 , 6 )) --math.random() is unreliable especially when u constantly select new random numbers |
09 | indiUI.Text = random |
10 | task.wait(waitTime) --task.wait() is just an improved version of wait() |
11 | end |
i just modified @Sw3atyEgirl's code a lil bit, credits to her