Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the GUI's text not changing?

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

✓ Accepted answer

#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

1 comment

0

It works, thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.