Yes, I know the basic of creating a gui. This is the script I have so far:
local plr = game.Players.LocalPlayer local CashLabel = script.Parent.Parent.CashLabel local leaderstats = game.Players.LocalPlayer.leaderstats while wait() do plr.leaderstats.Cash.Value = script.Parent.Parent.CashLabel end leaderstats.Cash.Changed:connect(function() leaderstats:SetAsync(plr.UserId, leaderstats.Cash.Value) end)
So basically, I wanted to make it where whatever their "leaderstats" is it will than display the value inside the textlabel of the gui.
I want to too keep running the script but I just never found out to do that, Instead of updating every 5 seconds or whatever.
Hello,
If you want it to keep updating you need to put it on a loop.
Here is the fixed code:
local plr = game.Players.LocalPlayer local CashLabel = script.Parent.Parent.CashLabel local leaderstats = game.Players.LocalPlayer.leaderstats while wait() do CashLabel.Text = leaderstats.Cash.Value plr.leaderstats.Cash.Value = script.Parent.Parent.CashLabel end while wait() do leaderstats.Cash.Changed:Connect(function() leaderstats:SetAsync(plr.UserId, leaderstats.Cash.Value) end) end
~Frag
Hey, what's up?
I see problems with your code, especially with my confusion on whether or not this is a LocalScript or a ServerScript, since you're :SetAsync'ing which can only be accessed by the sever, and changing TextLabels which logically should only be done on the client. (Your DataStores are also done incorrectly)
Putting that aside, I'll just be answering your question, specifically with this block of code:
while wait() do plr.leaderstats.Cash.Value = script.Parent.Parent.CashLabel end
All TextLabels have a .Text property, which displays their text. Naturally, this is how you'd manipulate it:
script.Parent.Parent.CashLabel.Text = "Test"
So with your current code, I would change it to something like this
while wait() do script.Parent.Parent.CashLabel.Text = plr.leaderstats.Cash.Value end
I would not suggest looping & changing it every 1/30 of a second. It's mostly inefficient. Use the .Changed event:
plr.leaderstats.Cash.Changed:Connect(function() script.Parent.Parent.CashLabel.Text = plr.leaderstats.Cash.Value end) -- this will also update instantly
Also, don't forget to add in some variables. Less variables is more efficient, but no variables at all is completely bad practice:
local cashLabel = script.Parent.Parent.CashLabel plr.leaderstats.Cash.Changed:Connect(function() cashLabel.Text = plr.leaderstats.Cash.Value end)
Hope I've helped!
no every one here is wrong its simple you have a number right as your cash but TEXTlabels only take strings or text so there is a function called tostring()
heres how it works
textlabel.Text = tostring(plr.leaderstats.Cash.Value)
lets say you want to get the number from the string well heres what you do
plr.leaderstats.Cash.Value = tonumber(textlabel.Text)