Datastoreservice causing saving over players' data

so i am trying to make a BSS fangame, however my datastores clash with eachother.
by that i mean that well, they cant tell eachother apart, and cause overwriting others’ data.
my code:

local Players = game:GetService("Players")
local DatastoreService = game:GetService("DataStoreService")

local database = DatastoreService:GetDataStore("data15")
local sessionData = {}

function PlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	local honey = Instance.new("IntValue")
	honey.Name = "Honey"
	honey.Parent = leaderstats
	
	local tool = Instance.new("NumberValue")
	tool.Name = "Tool"
	tool.Parent = player
	
	local pollen = Instance.new("IntValue")
	pollen.Name = "Pollen"
	pollen.Parent = leaderstats
	
	local digrate = Instance.new("NumberValue")
	digrate.Name = "Dig Rate"
	digrate.Parent = player
	
	local digspeed = Instance.new("NumberValue")
	digspeed.Name = "Dig Speed"
	digspeed.Parent = player
	
	local wpolmul = Instance.new("NumberValue")
	wpolmul.Name = "White Pollen Multiplier"
	wpolmul.Parent = player
	local rpolmul = Instance.new("NumberValue")
	rpolmul.Name = "Red Pollen Multiplier"
	rpolmul.Parent = player
	local bpolmul = Instance.new("NumberValue")
	bpolmul.Name = "Blue Pollen Multiplier"
	bpolmul.Parent = player
	local newbie = Instance.new("ObjectValue")
	newbie.Name = "New Bie"
	newbie.Value = nil
	newbie.Parent = player
	
	local success = nil
	local playerData = nil
	local attempt = 1
	
	repeat
		success, playerData = pcall(function()
			return database:GetAsync(player.UserId)
		end)

		attempt += 1
		if not success then
			warn(playerData)
			task.wait(3)
		end
	until success or attempt == 10
	
	if success then
		print("Connected to database")
		if not playerData then
			print("Assigning default data")
			playerData = {
				["Honey"] = 0,
				["DigRate"] = 0.1,
				["DigSpeed"] = 4,
				["WPolMul"] = 1,
				["RPolMul"] = 1,
				["BPolMul"] = 1,
				["Tool"] = 1,
				["Hive"] = {"Basic Bee"},
			}
		end
		sessionData[player.UserId] = playerData
			newbie.Changed:Connect(function()
			table.insert(playerData.Hive, newbie.Value.Name)
				game.ReplicatedStorage.LoadBees:FireClient(player, playerData.Hive)
				newbie.Value = nil
			end)
		honey.Value = playerData.Honey
		honey.Changed:Connect(function()
			playerData.Honey = honey.Value
		end)
		digrate.Value = playerData.DigRate
		digrate.Changed:Connect(function()
			playerData.DigRate = digrate.Value
		end)
		tool.Value = playerData.Tool
		tool.Changed:Connect(function()
			playerData.Tool = tool.Value
		end)
		digspeed.Value = playerData.DigSpeed
		digspeed.Changed:Connect(function()
			playerData.DigSpeed = digspeed.Value
		end)
		wpolmul.Value = playerData.WPolMul
		wpolmul.Changed:Connect(function()
			playerData.WPolMul = wpolmul.Value
		end)
		rpolmul.Value = playerData.RPolMul
		wpolmul.Changed:Connect(function()
			playerData.RPolMul = rpolmul.Value
		end)
		bpolmul.Value = playerData.BPolMul
		wpolmul.Changed:Connect(function()
			playerData.BPolMul = bpolmul.Value
		end)
		print(playerData.Hive)
		game.ReplicatedStorage.LoadBees:FireClient(player, playerData.Hive)
		game.ReplicatedStorage.GiftBees.OnServerEvent:Connect(function(Player)
			game.ReplicatedStorage.ClaimBees:FireClient(player, playerData.Hive)
		end)
	else
		warn("Unable to get data for", player.Name)
		player:Kick("Unable to load data, please rejoin if you can")
	end
	
	leaderstats.Parent = player
end

Players.PlayerAdded:Connect(PlayerAdded)

function PlayerLeaving(player)
	if sessionData[player.UserId] then
		local success = nil
		local errorMsg = nil
		local attempt = 1
		
		repeat
			success, errorMsg = pcall(function()
				database:SetAsync(player.UserId, sessionData[player.UserId])
			end)
			
			attempt += 1
			if not success then
				warn(errorMsg)
				task.wait(3)
			end
		until success or attempt == 10
		
		if success then
			print("Data saved for", player.Name)
		else
			warn("Unable to save for", player.Name)
		end
	end
end
Players.PlayerRemoving:Connect(PlayerLeaving)

Can you elaborate further on this? The Code doesn’t seem to have any issues as far as I can see that would result in Data overwrites. Do you have any other usage of DSS in your game?

no.
the problem is, the datastores load and sometimes even replace peoples stuff.
this can lock people in the 5/10 bee zones.

Replace with what? Other players data or with the template?

1 Like

other players
i mean that when the data loads, it erases like, half of the entire server’s data.
i mean that basically only the bees are (probably) saved for everyone, whilst when someone unlocks something, most server sided stuff is the same for everyone!