So I have scripts for my data stores and my leaderstats that only seem to work 20% of the time. In studio the data stores work like 60% of the time but in the actual game I haven’t seen them work once. The leaderstats when in game, if you KO someone ten times, it will only give you a couple KOs.
Here is my leaderstats script;
local RE = game.ReplicatedStorage.Events.DiedEvent
local Players = game.Players
local Template = Instance.new 'Folder'
Template.Name = 'leaderstats'
Instance.new('IntValue', Template).Name = "KO"
Instance.new('IntValue', Template).Name = "WO"
Instance.new("IntValue", Template).Name = "SNOWBALLS"
Players.PlayerAdded:connect(function(Player)
wait(1)
local leaderstats = Template:Clone()
leaderstats.Parent = Player
local WO = leaderstats.WO
RE.OnServerEvent:Connect(function(player)
local Character = Player.Character
player.leaderstats.WO.Value += 1
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.Died:connect(function()
for i, Child in pairs(Humanoid:GetChildren()) do
if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
local Killer = Child.Value
if Killer:FindFirstChild('leaderstats') and Killer.leaderstats:FindFirstChild("KO") then
local Multiplier = Killer:WaitForChild("Multiplier").Value
local SNOWBALLS = Killer.leaderstats.SNOWBALLS
local KO = Killer.leaderstats.KO
KO.Value += 1
SNOWBALLS.Value += 5 * Multiplier
end
return
end
end
end)
end
end)
end)
And here is my data store script;
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ItemData")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
if leaderstats then
local plrkey = "id_"..plr.UserId
local Save1 = leaderstats:FindFirstChild("KO")
local Save2 = leaderstats:FindFirstChild("SNOWBALLS")
print(Save1.Name)
print(Save2.Name)
local GetSaved = DataStore:GetAsync(plrkey)
if GetSaved then
Save1.Value = GetSaved[1]
Save2.Value = GetSaved[2]
print(Save1.Value)
print(Save2.Value)
print("Data Retrieved!")
else
local NumberForSaving = {Save1.Value, Save2.Value}
DataStore:GetAsync(plrkey, NumberForSaving)
end
else
print("'leaderstats' is nil!")
end
while wait(60 * 5) do
DataStore:SetAsync("id_"..plr.UserId, {plr.leaderstats.KO.Value, plr.leaderstats.SNOWBALLS.Value})
print("Data Saved!")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DataStore:SetAsync("id_"..plr.UserId, {plr.leaderstats.KO.Value, plr.leaderstats.SNOWBALLS.Value})
print("Data Saved!")
end)