Datastore issues

So Im trying to make a KO/WO system that saves but the datastores just don’t seem to save or load and im not sure why. heres what i have currently:

local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local killstore = DSS:GetDataStore("kills")
local deathstore = 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

	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)
1 Like

Your first mistake is this. You’re requiring the same DataStore twice. This messes up the whole system. You should just make a single data store, and then use a dictionary to save the kills and deaths.

2 Likes

can’t i just use 2 datastores? (ik its not advised but will it work?)
also u say thats the first problem does that mean theres more?

There is more problem, but regarding your request, yes it works but please don’t as you should know the limits of data stores.

But the thing is you are getting the same data store for both of your gems and gold value.

I tested it with 2 sepperate datastores and it didn’t work still. I also tried to do one datastore as a table but couldn’t figure it out. Could you give me an example or something that could help me to make it work?

If you are testing this from studio, are API services enabled?

i have api services enabled but also im testing in full game

Am i like accessing datastores incorrectly cause for some reason its just not working and I haven’t been able to figure out my issue via tutorials

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.

i already fixed that

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)

and it still just doesn’t work for some reason

1 Like

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)

Have you got API Services on in game?

yes I do indeed have api services enabled ingame and in studio (fancy words for char limit)

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.

would now be a good time to say this is my first time using pcalls?

1 Like
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)

image

what about saved prints? or they didn’t print anything?

image

Oh wait, i did mistake, lemme edit message with print’s, try edited message.