I have two scripts, One the local script that is inside the TextLabel which has the purpose of changing the text label so It is equal to the players Balance which is on the leaderstats. The other script is the overall leaderstat which is supposed to increase by .50 every second. First time trying to work with leaderstats.
LeaderStat Script [] Meant to increase by .5 every second(which didn't work)
game.Players.PlayerAdded:connect(function(player) local folder = Instance.new("Folder",player) folder.Name= "leaderstats" local Balance = Instance.new("IntValue",folder) Balance.Name="Balance" Balance.Value = 0 while true do wait(1) Balance.Value = Balance.Value + .5 end end)
TextLabel Script [] Meant to change the gui so it is equal to the players leaderstat Balance(which also didn't work)
local gui = script.Parent gui.Text = "Balance:"..game.Players.LocalPlayer.leaderstats.Balance.Value
Note The leaderstat script is in the Workspace and the TextLabel LocalScript is under the TextLabel which is under the Frame which is under the ScreenGui which is obviously under StarterGui.
game:GetService("Players").PlayerAdded:Connect(function(player) -- Switch to :Connect, :connect is deprecated local folder = Instance.new("Folder") -- parent argument is deprecated folder.Name= "leaderstats" folder.Parent = player -- always assign parent last local Balance = Instance.new("IntValue") Balance.Name= "Balance" Balance.Value = 0 Balance.Parent = folder while true do wait(1) Balance.Value = Balance.Value + 5 -- You made an IntValue, use NumberValue if you want .5 end end)
local plr = game:GetService("Players").LocalPlayer local ls = plr:WaitForChild("leaderstats") ls.Balance.Changed:Connect(function(value) script.Parent.Text = "Balance: " .. value end)
So if you want this work so use these scripts:
Leaderstats
function PlayerAdded(player) local folder = Instance.new("Folder",player) folder.Name= "leaderstats" local Balance = Instance.new("IntValue",folder) Balance.Name="Balance" Balance.Value = 0 while true do wait(1) Balance.Value = Balance.Value + .5 end end game.Players.PlayerAdded:Connect(PlayerAdded)
TextLabel
local gui = script.Parent while wait(0) do gui.Text = "Balance:".. game.Players.LocalPlayer.leaderstats.Balance.Value end