local label = script.Parent --varaible for less typing while true do --changed to while statement label.Text = ('Gold:' .. game.Players.LocalPlayer.leaderstats.Gold) print("Working!") end
i am currently working on a GUI that types the amount of Gold the player has. Any ideas?
You need to access the .Value
of Gold, and convert it to a string. Your code should look like:
local label = script.Parent --varaible for less typing while wait() do --changed to while statement(less laagy) label.Text = ('Gold:' .. tostring(game.Players.LocalPlayer.leaderstats.Gold.Value)) print("Working!") end
You are concatenating a string with an object, while strings can only be concatenated with strings. Here's the fixed version:
local label = script.Parent --varaible for less typing while true do --changed to while statement label.Text = ('Gold:' .. game.Players.LocalPlayer.leaderstats.Gold.Value) print("Working!") end
Basically, what I mean with what I just said before, is that you can do this:
E = 'Test' print( E .. 'Double' ) -- prints out TestDouble
but not this:
E = 'Test' print( E .. workspace.Double ) -- Errors
This is because you tried to concatenate an object, and wrapped your string in brackets. Brackets are math exclusive. Instead of using a loop to update the text, use the Changed
event to update it. The loop isn’t fast enough to get it updated.
local plr = game:GetService('Players').LocalPlayer local stats = plr:WaitForChild'leaderstats' local gold = stats.Gold gold.Changed:Connect(function() -- use this instead of loop script.Parent.Text = "Gold: "..gold.Value -- don’t wrap your string in brackets () since brackets are math exclusive. end)