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
4 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:

01game.Players.PlayerAdded:Connect(function(plr)
02    local coins = plr:WaitForChild("Currency").Coins
03    print("a")
04 
05    script.Parent.Text = coins.Value
06    print("a2")
07    coins:GetPropertyChangedSignal("Value"):Connect(function()
08        script.Parent.Text = coins.Value
09        print("a3")
10    end)
11end)

1 answer

Log in to vote
1
Answered by 4 years ago

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

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

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 — 4y
Ad

Answer this question