local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("LeaderStats")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local plrkey = "id_"..plr.userId
local Kills = Instance.new("IntValue",leaderstats)
Kills.Name = "Kills"
local XP = Instance.new("IntValue",leaderstats)
XP.Name = "XP"
local EXP = Instance.new("IntValue",leaderstats)
EXP.Name = "EXP"
local Rank = Instance.new("IntValue",leaderstats)
Rank.Name = "Rank"
local CR = Instance.new("IntValue",leaderstats)
CR.Name = "CR"
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-KILLS")
end)
if success then
Kills.Value = data
else
print("There Was An Error Whilst Getting Your Data")
warn(errormessage)
end
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-KILLS")
end)
if success then
XP.Value = data
else
print("There Was An Error Whilst Getting Your Data")
warn(errormessage)
end
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-XP")
end)
if success then
EXP.Value = data
else
print("There Was An Error Whilst Getting Your Data")
warn(errormessage)
end
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-EXP")
end)
if success then
Rank.Value = data
else
print("There Was An Error Whilst Getting Your Data")
warn(errormessage)
end
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-RANK")
end)
if success then
CR.Value = data
else
print("There Was An Error Whilst Getting Your Data")
warn(errormessage)
end
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-CR")
end)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:FindFirstChild("Humanoid")
if humanoid then
humanoid.Died:Connect(function()
for i, Chill in pairs(humanoid:GetChildren()) do
if Chill:IsA("ObjectValue") and Chill.Value and Chill.Value:IsA("Player") then
local Killer = Chill.Value
Killer.leaderstats.Kills.Value = Killer.leaderstats.Kills.Value + 1
Killer.leaderstats.XP.Value = Killer.leaderstats.XP.Value + 100
while humanoid.Running:Wait() do
Killer.leaderstats.XP.Value = Killer.leaderstats.XP.Value + 100
end
end
end
end)
end
end)
while wait() do
EXP.Value = plr.leaderstats.Rank.Value*1000+1000
if XP.Value >= EXP.Value then
XP.Value = XP.Value - EXP.Value
Rank.Value = plr.leaderstats.Rank.Value + 1
CR.Value = CR.Value + 200+5*Rank.Value
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-KILLS",player.leaderstats.Kills.Value)
end)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-XP",player.leaderstats.XP.Value)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-EXP",player.leaderstats.EXP.Value)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-RANK",player.leaderstats.Rank.Value)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-CR",player.leaderstats.CR.Value)
if success then
print("Player Data Successfully Saved!")
else
print("There Was An Error When Saving Data")
warn(errormessage)
end
end)
end)
end)
end)
end)
This Script is Glitching Out For Me I Made It Myself and i don't know how to fix it do you know how to fix it. when ever i use it it says EXP -9,220..... XP is blicking -9,220..... and Rank is -9,220..... Can Anyone Help Me Fix This Script Please?

1 comment
I wouldn't even bother fixing that, it looks unnecessarily long, i am ssuming you just want leaderstats that save, so I will provide an answer