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

How would I make someone's amount of money print on a GUI's TextLabel?

Asked by 4 years ago

Code I have so far:

game.Players.PlayerAdded:Connect(function()
    game.StarterGui:FindFirstChild("Money")
    if Money.Value == 0 then 
        game.StarterGui.MoneyGUI.MoneyFrame.MoneyText.Text = ("'No world means NO MONEY!' -Mr. Krabs")
    elseif game.Players.Money > 0 then
        game.StarterGui.MoneyGUI.MoneyFrame.MoneyText.Text = game.Players.Money     
    end 
end)

It doesn't work. It leaves the TextLabel (MoneyText) saying 'Label'. What am I doing wrong? Shouldn't its text change to 'No world means NO MONEY! -Mr Krabs'?

1 answer

Log in to vote
0
Answered by 4 years ago

I'm a bit confused. You did Money.Value == 0 but on the second argument, you used game.Players.Money > 0? On the second one, you are checking inside of the Player directory. And the StarterGui is the wrong directory. If you want to change a GUI text you need to change the one located in PlayerGui. Here's some code that should help you a bit.

game.Players.PlayerAdded:Connect(function(Player)
    local PlayerGui = Player:WaitForChild("PlayerGui")
    local Money = Player:WaitForChild("Money")
    local MoneyGUI = PlayerGui:WaitForChild("MoneyGUI")
    if Money.Value <= 0 then 
        MoneyGUI.MoneyFrame.MoneyText.Text = ("'No world means NO MONEY!' -Mr. Krabs")
    else
        MoneyGUI.MoneyFrame.MoneyText.Text = Money.Value   
    end 
end)

That won't automatically update though. And that is assuming the Money is located inside of the player and not in a different folder.

0
I think on the second argument I forgot to put Value after money sean_thecoolman 189 — 4y
Ad

Answer this question