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

Why is the GUI's text not changing?

Asked by 4 years ago

I want to change the GUI's text to cash, but it never changes and gives no errors. The leaderstats changes but the GUI does not. The script is located in starter character scripts.

wait(1)
local playerModel = script.Parent
local player = game.Players:GetPlayerFromCharacter(playerModel)

player:WaitForChild("leaderstats")
player.leaderstats:WaitForChild("Cash") 
local cash = player.leaderstats.Cash
local moneyText = player.PlayerGui.ScreenGui.moneyLabel.Text

while true do
wait(5)
    cash.Value = cash.Value + 100
    moneyText = cash.Value
end

Does anyone know how to fix this? Thanks in advance!

1 answer

Log in to vote
0
Answered by 4 years ago

Problem

You set the Variable moneyText to player.PlayerGui.ScreenGui.moneyLabel.Text but Lua just Sets the variable to the property and when you set it it only changes the Variable itself. Not the actual property.

Solution

Replace player.PlayerGui.Screengui.moneyLabel.Text with player.PlayerGui.Screengui.moneyLabel. And replace moneyText = cash.Value to moneyText.Text = cash.Value

Final Script

wait(1)
local playerModel = script.Parent
local player = game.Players:GetPlayerFromCharacter(playerModel)

player:WaitForChild("leaderstats")
player.leaderstats:WaitForChild("Cash")
local cash = player.leaderstats.Cash
local moneyText = player.PlayerGui.ScreenGui.moneyLabel

while true do
    wait(5)
    cash.Value = cash.Value + 100
    moneyText.Text = cash.Value
end

0
It works, thanks pinkcust2vids 2 — 4y
Ad

Answer this question