Important problem with my session locking data script

Hello, I’ve followed This Tutorial for my datastore but I’m having a big problem. Only the first player who joins the game sees his data load, all the others are then on hold because of sessionlocking when they shouldn’t be. I’m lost and can’t figure out why this is happening. I’ll try to put the parts of the script below, readable, so you can understand my problem. Thank you very much.

So first there is the default data in case there is no data, you can see SessionLock is false

local default = {
	SessionLock = false,
	CoinsExemple = 0,
}

Then player join :

local function setUp(plr)
	local Coins = Instance.new('NumberValue')
	Coins.Name = 'Coins'
	Coins.Parent = plr
	local success, data, shouldWait
	repeat
		waitForRequestBudget()
		success = pcall(dataStore.UpdateAsync, dataStore, key, function(oldData)
			oldData = oldData or default
			if oldData.SessionLock and not RunService:IsStudio() then
				if os.time() - oldData.SessionLock < 1800 then --PROBLEME HERE, second player has sessionlock
					shouldWait = true
				else
					oldData.SessionLock = os.time()
					data = oldData
					return data
				end
			else
				oldData.SessionLock = os.time()
				data = oldData
				return data
			end
		end)
		if shouldWait then
			task.wait(5)
			shouldWait = false
		end
	until (success and data) or not Players:FindFirstChild(name)
end
--Then i load the value if success and data

Players.PlayerAdded:Connect(setUp)

It’s like the first player overwrite the default data and so the new players that come after him can’t load a new data … But there is nothing in the script that overwrite the default data for the new players

oldData = oldData or default

This is the part where you made a mistake. By setting “oldData” to “default” table it will make changes to the “default” table. What you need to do is to make a deep copy of the “default” table and set “oldData” to the copy.

Here is a function that returns a deepCopy of a table that is passed into it.

local function deepCopyTable(t : {})
	local copy = {}
	for key, value in pairs(t) do
		if type(value) == "table" then
			copy[key] = Shared.deepCopyTable(value)
		else
			copy[key] = value
		end
	end
	return copy
end

You can put this function at the top of your code or what i like to do is put it in a module it replicated storage.

That’s it hope it helped.