This is the Script that I use can someone improve this?
local Players = game:GetService("Players") local DataStore = game:GetService("DataStoreService") local DpointsData = DataStore:GetDataStore("DpointsData1") local RankData = DataStore:GetDataStore("RankData1") Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) local Player = game:GetService("Players").LocalPlayer local stats = Player:WaitForChild("leaderstats") local Dpoints = stats.Dpoints Dpoints.Value = DpointsData:GetAsync(Player.UserId) or 0 DpointsData:SetAsync(Player.UserId, Dpoints.Value) local Rank = stats.Rank Rank.Value = RankData:GetAsync(Player.UserId) or "Unrank" RankData:SetAsync(Player.UserId, Rank.Value) end) game.Players.PlayerRemoving:Connect(function(Player) DpointsData:SetAsync(Player.UserId, Player.leaderstats.Dpoints.Value) RankData:SetAsync(Player.UserId, Player.leaderstats.Rank.Value) end) game:BindToClose(function() DpointsData:SetAsync(Player.UserId, Player.leaderstats.Dpoints.Value) RankData:SetAsync(Player.UserId, Player.leaderstats.Rank.Value) end) end)
For starters, you should not use LocalPlayer in a server script. You should delete the Player.CharacterAdded function, it is not needed, then that should fix it.
local Players = game:GetService("Players") local DataStore = game:GetService("DataStoreService") local DpointsData = DataStore:GetDataStore("DpointsData1") local RankData = DataStore:GetDataStore("RankData1") Players.PlayerAdded:Connect(function(Player) local stats = Player:WaitForChild("leaderstats") local Dpoints = stats.Dpoints Dpoints.Value = DpointsData:GetAsync(Player.UserId) or 0 DpointsData:SetAsync(Player.UserId, Dpoints.Value) local Rank = stats.Rank Rank.Value = RankData:GetAsync(Player.UserId) or "Unrank" RankData:SetAsync(Player.UserId, Rank.Value) end) game.Players.PlayerRemoving:Connect(function(Player) DpointsData:SetAsync(Player.UserId, Player.leaderstats.Dpoints.Value) RankData:SetAsync(Player.UserId, Player.leaderstats.Rank.Value) end) game:BindToClose(function() DpointsData:SetAsync(Player.UserId, Player.leaderstats.Dpoints.Value) RankData:SetAsync(Player.UserId, Player.leaderstats.Rank.Value) end)