local DataStoreService = game:GetService("DataStoreService") local T1 = DataStoreService:GetDataStore("SavePoints") game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = Player local Point = Instance.new("IntValue") Point.Name = "Points" Point.Parent = leaderstats end) game.Players.PlayerRemoving:Connect(function(player) pcall(function() T1:SetAsync(player.UserId.."-Points",player.leaderstats["Points"].Value) print("Saved") end) end)
Is anything wrongs with it? because each times i leave and join again it'll reset my points back to 0 ! and not even a single saves in it? btw i already enable Studio Access to API Services
The reason is because you never load the stats in after they join.
game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder"); leaderstats.Name = "leaderstats"; leaderstats.Parent = Player; local info = T1:GetAsync(Player.UserId.."-Points); local Points = Instance.new("IntValue"); Points.Name = "Points"; Points.Parent = leaderstats; if(info) then Points.Value = tonumber(info); else T1:SetAsync(Player.UserId.."-Points", 0); Points.Value = 0; end end)