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

The textlabel displaying the players amount of gold stays at 0. Any Help?

When I try to make this filtering enabled script for the players number of gold to load. The number stays at 0 (The text I set it to by default)

Script inside the TextLabel displaying the players amount of gold:

text = script.Parent.Text

game.ServerStorage.loadGold:FireServer(text)

The script inside StarterPlayerScripts controlling the RemoteServer:

plr = game.Players.LocalPlayer

function loadGold(text)
	while true do
		wait(0.1)
		text = plr.Stats.Gold.Value
	end
end

game.ServerStorage.loadGold.OnServerEvent:connect(loadGold())

2 answers

So, I have also been having issues with these things but I'd use player added

game.Players.PlayerAdded:connect(function(plr)

function loadGold(text)
    while true do
        wait(0.1)
        text = plr.Stats.Gold.Value
    end
end
game.ServerStorage.loadGold.OnServerEvent:connect(loadGold())
end)

Hello, the answer above would work but there is a better way and it's much better because it doesn't require a loop. If you have lots of scripts and they contain while true do or while wait do then it has a chance of causing the entire game to crash, my method or the better way of doing this is called the Changed event which will fire when the value is changed;

I will write a script and tell you what it does;

First, make sure this is a Local Script then add it into the TextLabel if it's in the player Gui;

local plr = game.Players.LocalPlayer
local g = plr:WaitForChild('Stats').Gold -- we use waitforchild to wait for the child to load
local gT = game.ServerStorage:WaitForChild('loadGold') -- this line is where the TextLabel is you can change it

gT.Text = g.Value -- set's the value on join

g.Changed:Connect(function() -- this will function when g's value has changed
	gT.Text = g.Value -- set's the value
end)

The script above will set the text to the value on join then like a loop every time g's value changes, the text will change.

If this helped you understand, learn or at least helped you then please accept answer ;)

Good luck and have fun developing!

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