this is my code...
Players.PlayerAdded:Connect(leaderbaordFunction)
local r = game.ReplicatedStorage.Click
r.OnServerEvent:Connect(function(player) player.leaderstats.Strenght.Value = player.leaderstats.Strenght.Value + 5 end)
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local Strenght = Instance.new("IntValue")
Strenght.Name = "Strenght"
Strenght.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
--Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
if data then
Cash.Value = data.Cash
Strenght.Value = data.Strenght
-- Load the data from last time you played the game
end
end
end)
game.Players.PlayerRemoving:Connect(function(player) local playerUserId = "Player_"..player.UserId
local data = {
Cash = player.leaderstats.Cash.Value;
Strenght = player.leaderstats.Strenght.Value;
}
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data Saved")
else
print("There was an error while saving data ")
warn(errormessage)
end
end)
