I'm trying to set up a GUI to take the value of a leaderboard stat but it's not working for some reason.
while true do script.Parent.CreditValue.Text=player.leaderstats.Credits.Value end wait(1)
There are a few issues with this script, as well as a better method to using it, but I will tackle one thing at a time:
First, you have a wait() function outside of the loop. This should be moved to the inside, like this:
while true do wait(1) script.Parent.CreditValue.Text=player.leaderstats.Credits.Value end
Second, something that is possibly an issue is that you are trying to put an IntValue
/ NumberValue
into a String
property. The best way to fix this issue is this:
while true do wait(1) script.Parent.CreditValue.Text=tostring(player.leaderstats.Credits.Value) end
So that should fix your script, but you can take it a step further if you want to.
If you have ten players in a server, then you have ten loops running at the same time, which can easily slow down the server. To fix this, you can use the .Changed
event:
function changeOccurred(Property) script.Parent.CreditValue.Text=tostring(player.leaderstats.Credits.Value) end player.leaderstats.Credits.Changed:connect(changeOccurred)
Now, whenever the player's cash changes, the GUI will update itself instantly. I hope this helped!