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

Why does this local script not change my UI's text?

Asked by
D4_rrk 89
3 years ago

I have a local script that changes the UI's text depending on how much currency (coins) you have but when I try test it, I get no print messages and the text doesn't change at all! The UI is inside StarterGUI and the currency folder is inside the player (same place where you would have your leaderstats folder).

The local script:

game.Players.PlayerAdded:Connect(function(plr)
    local coins = plr:WaitForChild("Currency").Coins
    print("a")

    script.Parent.Text = coins.Value
    print("a2")
    coins:GetPropertyChangedSignal("Value"):Connect(function()
        script.Parent.Text = coins.Value
        print("a3")
    end)
end)

1 answer

Log in to vote
1
Answered by 3 years ago

Move local script to the GUI text label that you want. Try this code instead!

while wait() do
    local player = game.Players.LocalPlayer
    script.Parent.Text = player:WaitForChild("leaderstats"):FindFirstChild("Coins").Value
end

Make sure the leaderstats folder (Instance.new created by leaderstats script) is named leaderstats or else edit my script yourself.

0
Turns out all I had to do was replace game.Players.PlayerAdded:Connect(function(plr) with local plr = game.Players.LocalPlayer D4_rrk 89 — 3y
Ad

Answer this question