local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local killstore = DSS:GetDataStore("kills")
local deathstore = DSS:GetDataStore("kills")
Why are you calling for the same DataStore “kills” for two globals?
Instead, make one DataStore for storing the Deaths, and one DataStore for the kills, which is GetDataStore("kills").
Note:
Make sure you’ve enabled also API Services and HTTP Requests.
local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local killstore = DSS:GetDataStore("kills")
local deathstore = DSS:GetDataStore("deathstore")
game.Players.PlayerAdded:Connect(function(player)
-- Checks if player is KO'd, please ignore --
local kod = Instance.new("BoolValue")
kod.Name = "KO"
kod.Parent = player
--------------------------------------------------------
-- Checks if player is being carried, please ignore --
local carried = Instance.new("BoolValue")
carried.Name = "Carried"
carried.Parent = player
--------------------------------------------------------
-- Checks if player is ragdolled, please ignore --
local ragdoll = Instance.new("BoolValue")
ragdoll.Name = "Ragdoll"
ragdoll.Parent = player
--------------------------------------------------------
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local kills = Instance.new("NumberValue",leaderstats)
kills.Name = "kills"
local kill
local success, notSuccess = pcall(function()
kill = killstore:GetAsync(player.UserId)
if kill == nil then kill = 0 end
end)
if success then
kills.Value = kill
end
local deaths = Instance.new("NumberValue",leaderstats)
deaths.Name = "deaths"
local death
local success, notSuccess = pcall(function()
death = deathstore:GetAsync(player.UserId)
if death == nil then death = 0 end
end)
if success then
deaths.Value = death
end
player.CharacterAdded:connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Died:Connect(function(died)
deaths.Value = deaths.Value + 1
local success, notSuccess = pcall(function()
deathstore:SetAsync(player.UserId,player.leaderstats.deaths.Value)
end)
local tag = humanoid:FindFirstChild("creator")
local killer = tag.Value
if tag and killer then
killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("kills").Value + 1
local success, notSuccess = pcall(function()
killstore:SetAsync(killer.UserId,killer.leaderstats.kills.Value)
end)
end
end)
end)
end)
I tried doing the same code that i have but with only one of the datastores and it still doesn’t work at all
does anyone have an example of a script that acesses a datastore and works?
local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local killstore = DSS:GetDataStore("kills")
game.Players.PlayerAdded:Connect(function(player)
-- Checks if player is KO'd, please ignore --
local kod = Instance.new("BoolValue")
kod.Name = "KO"
kod.Parent = player
--------------------------------------------------------
-- Checks if player is being carried, please ignore --
local carried = Instance.new("BoolValue")
carried.Name = "Carried"
carried.Parent = player
--------------------------------------------------------
-- Checks if player is ragdolled, please ignore --
local ragdoll = Instance.new("BoolValue")
ragdoll.Name = "Ragdoll"
ragdoll.Parent = player
--------------------------------------------------------
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local kills = Instance.new("NumberValue",leaderstats)
kills.Name = "kills"
local kill
local success, notSuccess = pcall(function()
kill = killstore:GetAsync(player.UserId)
if kill == nil then kill = 0 end
end)
if success then
kills.Value = kill
end
player.CharacterAdded:connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
local tag = humanoid:FindFirstChild("creator")
local killer = tag.Value
if tag and killer then
killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("kills").Value + 1
local success, notSuccess = pcall(function()
killstore:SetAsync(killer.UserId,killer.leaderstats.kills.Value)
end)
end
end)
end)
Print something when it saves succesfully or load succesfully. If something doesn’t print, then thats the problem, and we will have less things to find out why it doesn’t work.
local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local killstore = DSS:GetDataStore("kills")
local deathstore = DSS:GetDataStore("deathstore")
game.Players.PlayerAdded:Connect(function(player)
-- Checks if player is KO'd, please ignore --
local kod = Instance.new("BoolValue")
kod.Name = "KO"
kod.Parent = player
--------------------------------------------------------
-- Checks if player is being carried, please ignore --
local carried = Instance.new("BoolValue")
carried.Name = "Carried"
carried.Parent = player
--------------------------------------------------------
-- Checks if player is ragdolled, please ignore --
local ragdoll = Instance.new("BoolValue")
ragdoll.Name = "Ragdoll"
ragdoll.Parent = player
--------------------------------------------------------
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local kills = Instance.new("NumberValue",leaderstats)
kills.Name = "kills"
local kill
local success, notSuccess = pcall(function()
kill = killstore:GetAsync(player.UserId)
if kill == nil then print("No savings") kill = 0 end
end)
if success then
print("Loaded")
kills.Value = kill
end
local deaths = Instance.new("NumberValue",leaderstats)
deaths.Name = "deaths"
local death
local success, notSuccess = pcall(function()
death = deathstore:GetAsync(player.UserId)
if death == nil then print("No savings") death = 0 end
end)
if success then
print("Loaded")
deaths.Value = death
end
player.CharacterAdded:connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Died:Connect(function(died)
deaths.Value = deaths.Value + 1
local success, notSuccess = pcall(function()
deathstore:SetAsync(player.UserId,player.leaderstats.deaths.Value)
end)
if success then
print("Saved")
end
local tag = humanoid:FindFirstChild("creator")
local killer = tag.Value
if tag and killer then
killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("kills").Value + 1
local success, notSuccess = pcall(function()
killstore:SetAsync(killer.UserId,killer.leaderstats.kills.Value)
end)
if success then
print("Saved")
end
end
end)
end)
end)