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

Why is my TextButton not changing its text?

Asked by 2 years ago
Edited 2 years ago

Hey! I wrote a script that has worked hundreds of times before but now it doesn't all of a sudden, the main goal is to change the text every second. This may just be a bug on Roblox's end but I wanted to check here in case I am missing something. The code:

local labeltext = script.Parent.Text
game.ChildAdded:Connect(function(plr)
    print(script.Parent.Name)
    labeltext = "Lava rising in: 10"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 9"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 8"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 7"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 6"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 5"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 4"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 3"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 2"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising in: 1"
    wait(1)
    print(script.Parent.Text)
    labeltext = "Lava rising!"
    print(script.Parent.Text)
end)

Here is what happens:

https://imgur.com/a/Zltr7W1

Thanks in advance!

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

The issue here is that you're not actually changing the text, you're just storing it to the variable...

To make it easier so you don't have to do labeltext.Text every time you want to change the text, I'd recommend using a function.

Also, you can make this a lot shorter and easier by using a for loop to update the text for every iteration, instead of repeating yourself for every line when you want to update the text.

local labeltext = script.Parent

local function UpdateText(str)
    labeltext.Text = str
end

game.Players.ChildAdded:Connect(function(plr) -- Did you mean game.Players?
    for t = 10, 1, -1 do
        UpdateText("Lava rising in: "..t)
        print(script.Parent.Text)
        wait(1)
    end
    UpdateText("Lava rising!")
end)
Ad

Answer this question