How would I make this actually save? At the moment it only saves in the server at the moment. How would I make it save, for the whole game?
game.Players.PlayerAdded:connect(function(player)
local saveData = game.RobloxReplicatedStorage:FindFirstChild(player.Name)
if not saveData then
wait (1)
local newSave = Instance.new ("Folder")
newSave.Parent = game.RobloxReplicatedStorage
newSave.Name = player.Name
local coins = Instance.new ("NumberValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = newSave
local diamonds = Instance.new("NumberValue")
diamonds.Parent = newSave
diamonds.Name = "Gems"
diamonds.Value = 0
local playersStats = player:FindFirstChild("leaderstats")
local cash = playersStats:FindFirstChild("Coins")
local gems = playersStats:FindFirstChild("Gems")
cash.Value = coins.Value
gems.Value = diamonds.Value
else
wait (1)
local playerStats = player:FindFirstChild("leaderstats")
local cash = playerStats:FindFirstChild ("Coins")
local gems = playerStats:FindFirstChild("Gems")
if cash then
if gems then
cash.Value = saveData.Coins.Value
gems.Value = saveData.Gems.Value
if player.Name == "jdc892" then
cash.Value = cash.Value + 50
end
end
end
end
end)
game.Players.PlayerRemoving:connect (function(player)
local playerSave = game.RobloxReplicatedStorage:FindFirstChild(player.Name)
if playerSave then
local cashValue = playerSave:FindFirstChild("Cash")
if cashValue then
local gemsValue = playerSave:FindFirstChild("Gems")
if gemsValue then
local leaderStats = player:FindFirstChild ("leaderstats")
if leaderStats then
local playersCoins = leaderStats:FindFirstChild ("Coins")
local playersGems = leaderStats:FindFirstChild ("Gems")
if playersCoins then
if playersGems then
cashValue.Value = playersCoins.Value
gemsValue.Value = playersGems.Value
end
end
end
end
end
end
end)

1 comment
http://wiki.roblox.com/index.php?title=Saving_Player_Data