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

Text in TextLabel is not changing, how do I fix it?

Asked by
zGavinz 11
3 years ago

I'm completely confused on why my script will not work. I've tried changing the variables, but it just won't work.

wait()
local l = game.Players.LocalPlayer:WaitForChild("leaderstats").Level
local t = game.Players.LocalPlayer:WaitForChild("PlayerGui").Level.LevelName.Text
script.Level1:Play()
l:GetPropertyChangedSignal("Value"):Connect(function()

                if l.Value == 2 then
                    script.Level1:Stop()
            script.Level2:Play()
            t = "Level 2"

            else if l.Value == 3 then
                script.Level2:Stop()
            script.Level3:Play()
            t = "Level 3"

            end

        end
 end)

This LocalScript that has this code is in StarterPlayerScripts. In this code, I'm confused about the text changing, not the sound playing/stopping.

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

On the third line you are defining the variable wrong, you are defining text of the label, but you don't do that, instead define the text label and then do t.Text = "Blablabla". Just like you have done with the value. Another issue is that if it is local script then when you will play the game you will most likely have an error that you tried to index nil, because the script ran before they loaded, for that, use WaitForChild()

0
Ah, that makes sense now. Thanks! zGavinz 11 — 3y
Ad

Answer this question