I made a youtube tutorial on how you can do this. Just follow step by step and it should work. You do have to customize this to get your points and xp value and stuff.
If you have trouble saving BOTH those values, then leave a post and I will help.
I made a youtube tutorial on how you can do this. Just follow step by step and it should work. You do have to customize this to get your points and xp value and stuff.
If you have trouble saving BOTH those values, then leave a post and I will help.
I know this has been solved but you could use this.
This will fully work.
local Players = game:GetService("Players") -- Main | Players
local DataStoreService = game:GetService("DataStoreService") -- DataStoreService
local Data = {Points = DataStoreService:GetDataStore("Points"), XP = DataStoreService:GetDataStore("Experience")} -- data
local DebugMode = true -- [Disable/Set to false ] if you don't want to see warn(msg) in output
function Add(Player)
local ldr = Instance.new("Folder")
ldr.Parent = Player
ldr.Name = "leaderstats"
local PointsVal = Instance.new("IntValue")
PointsVal.Parent = ldr
PointsVal.Name = "Points"
PointsVal.Value = Data.Points:GetAsync(tostring(Player.UserId)) or 0 -- at 0, set starter points
local XPval = Instance.new("IntValue")
XPval.Parent = ldr
XPval.Name = "XP"
XPval.Value = Data.XP:GetAsync(tostring(Player.UserId)) or 0 -- at 0, set starter XP
while wait(60) do
Data.Points:SetAsync(tostring(Player.UserId), PointsVal.Value)
Data.XP:SetAsync(tostring(Player.UserId), XPval.Value)
if DebugMode then
warn("Stats have been saved! Player > "..Player.Name.." [AutoSave]") -- Check Output
end
end
end
function Leave(Player)
if DebugMode then
warn("Stats have been saved to "..Player.Name..", they left the game! [AutoSave]") -- Check Output
end
Data.Points:SetAsync(tostring(Player.UserId), Player:WaitForChild("leaderstats"):WaitForChild("Points").Value) -- saving value on leave
Data.XP:SetAsync(tostring(Player.UserId), Player:WaitForChild("leaderstats"):WaitForChild("XP").Value) -- saving value on leave
end
Players.PlayerAdded:Connect(Add)
Players.PlayerRemoving:Connect(Leave)