I want the GUI to display the players coins. I have tryed this and it dosent want to work?? Aneyone got a solution
Leaderboard:
game.Players.PlayerAdded:connect(function(player) stats = Instance.new ("IntValue", player) stats.Name = "leaderstats" coins = Instance.new ("IntValue", stats) coins.Name = "Coins" coins.Value = 10 end) game.Players.PlayerRemoving:connect(function(player) end)
GUI script:
while true do if script.Parent.Text == "0" then script.Parent.Text = game.Players.leaderstats.Coins.Value end end
Gui Script
local player = game.Players.LocalPlayer script.Parent.Text = player.leaderstats.Coins.Value -- added this line to initialise the gui. player.leaderstats.Coins.Changed:connect(function() script.Parent.Text = player.leaderstats.Coins.Value end) -- Wrapping your function like this ensure it only changes when the value changes, this is better than a while loop and is called an anonymous function.
I've defined player as a local value to match the games local player, this has to be in a localscript to work, localscripts should work fine inside of the players character, the current camera, the players backpack or the players gui.
In your GUI Script, on line 3, you aren't pointing to a player which is why it's not working. Make sure the GUI script is in a LocalScript and change line 3 to look like this: script.Parent.Text = game.Players.LocalPlayer.leaderstats.Coins.Value
. I hope this helps!
Make sure that you're testing this script online, as most leaderboard scripts don't work in solo mode. Also, don't forget to add a wait() just before the end in your while loop, if you don't it will cause your computer to run out of memory. Anyways, if it still doesn't work, is there anything in the output ?