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

How to display money in textlabel?

Asked by 2 years ago
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
if leaderstats then
    print(leaderstats)
    local MoneyValue = leaderstats:WaitForChild("Money")
    if MoneyValue then
        script.Parent.Text = MoneyValue .. "$"
    end 
end

its not working and not printing it and i don't know why

1 answer

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

I found multiple errors in your code. Also you was trying to print an Instance and you weren't updating the UI.

Here is the fixed code:

local player = game.Players.LocalPlayer 

local leaderstats = player:WaitForChild("leaderstats") 
 while wait(0.01) do
  if leaderstats then
     script.Parent.Text = leaderstats.Money.Value.."$"
end
end
0
Still says "Players.MrBucketOfficial.PlayerGui.ScreenGui.TextLabel.Script:1: attempt to index nil with 'WaitForChild' " MrBucketOfficial 39 — 2y
0
If the textlabel works, then ignore it. That happens because the script was activated first before the gane finished loading. That’s a common thing. If it doesn’t work klet me know and I might give a solution. T3_MasterGamer 2189 — 2y
0
game* T3_MasterGamer 2189 — 2y
0
It must be in a localscript SuperPuiu 497 — 2y
Ad

Answer this question