So I tried to make a script that saved your points, however the points does not save. I don't get any errors, nor do I get any errors in the game when I press F9. Any soloutions! Thanks!

local DataStore = game:GetService("DataStoreService"):GetDataStore("Points")

game:GetService("Players").PlayerAdded:connect(function(Player)
	local leaderstats = Instance.new("IntValue", Player)
	leaderstats.Name = "leaderstats"
	local cash = Instance.new("IntValue", leaderstats)
	local x = Instance.new("IntValue", leaderstats)
	cash.Name = "Level"
	cash.Value = 0
	x.Name = "XP"
	x.Value = 0
	local key = "user-"..Player.userId
    local SavedPoints = DataStore:GetAsync(key)
	if SavedPoints ~= nil then  
		cash.Value = SavedPoints[1]
		x.Value = SavedPoints[2]
	else
		local ValuesToSave = {cash.Value, x.Value}
		DataStore:SetAsync(key, ValuesToSave)
	end
	x.Changed:connect(function()
		cash.Value = math.floor(x.Value / 50)
	end)
end)
game.Players.PlayerRemoving:connect(function(plr)
	local key = "user-"..plr.userId
	local ValuesToSave = {plr.leaderstats.cash.Value,plr.leaderstats.x.Value}
	DataStore:SetAsync(key, ValuesToSave)
end)

1 comment

0

Might be closing the server before it has chance to save, check this out? http://wiki.roblox.com/index.php?title=API:Class/DataModel/OnClose