I've got this much from the wiki, I need help with the last part.
scoreKey = "PlayerScore" game.Players.PlayerAdded:connect(function(player) if player:WaitForDataReady() then local leaderstats = Instance.new("IntValue", player) leaderstats.Name = "leaderstats" local cash = Instance.new("IntValue", leaderstats) cash.Name = "Cash" cash.Value = player:LoadNumber(scoreKey) local xp = Instance.new("IntValue", leaderstats) xp.Name = "XP" xp.Value = player:LoadNumber(scoreKey) end end) game.Players.PlayerRemoving:connect(function(player) -- How do I change this so when you click a TextButton it will save your data? if player:findFirstChild("leaderstats") then player:SaveNumber(scoreKey, player.leaderstats.Score.Value) end end)
Make the script that you put this into a localscript (And put the localscript into the TextButton). Insert this into the script:
scoreKey = "PlayerScore" game.Players.PlayerAdded:connect(function(player) if player:WaitForDataReady() then local leaderstats = Instance.new("IntValue", player) leaderstats.Name = "leaderstats" local cash = Instance.new("IntValue", leaderstats) cash.Name = "Cash" cash.Value = player:LoadNumber(scoreKey) local xp = Instance.new("IntValue", leaderstats) xp.Name = "XP" xp.Value = player:LoadNumber(scoreKey) end end) function Clicked() local player=game.Player.LocalPlayer if player:findFirstChild("leaderstats") then player:SaveNumber(scoreKey, player.leaderstats.Score.Value) end end) script.Parent.MouseButton1Click:connect(Clicked)
It's the same thing, I just added a clicked event for the textbutton to save.