Datastore giving player another players money

Hello, I am pretty new to datstores asides from a car dealership I made a while ago. I am not sure why this issue is occuring. Here is my script. I know it is messy and inneficient, but I would like to get the framework done first. If I join a server that someone else is in, I get that players money saved to me.

local dss = game:GetService("DataStoreService")
local moneystore = dss:GetDataStore("Money")
game.Players.PlayerAdded:Connect(function(plr)
	 t = script.Bank:Clone()
	t.Value = moneystore:GetAsync(plr.UserId) or 63
	game.ReplicatedStorage.Globals.Day.Changed:Connect(function()
		t.Value = t.Value + 24
		moneystore:SetAsync(plr.UserId,t.Value)
		plr.PlayerGui.Menu.Notif.PushNotif:FireAllClients("UCS Payment","Your Universal Credit payment of £24 has been deposited.")
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	moneystore:SetAsync(plr.UserId, t.Value)
end)

As seen on the Datastore Editor plugin, 2 players have the exact same balance after being in a server together.

image
image
Any help is appreciated, Thanks.

Use pcall function when you getting / setting data.

Hi,
I added pcall()s but it did not resolve the issue.
Please review my code below

local dss = game:GetService("DataStoreService")
local moneystore = dss:GetDataStore("Money")
game.Players.PlayerAdded:Connect(function(plr)
	 t = script.Bank:Clone()
	t.Parent = plr
	local success = pcall(function()
		t.Value = moneystore:GetAsync(plr.UserId) or 63	
	end)
	game.ReplicatedStorage.Globals.Day.Changed:Connect(function()
		t.Value = t.Value + 24
		local success = xpcall(function()
			moneystore:SetAsync(plr.UserId,t.Value)
		end, warn)
		if success then
			print("SCOTWARE CORP. SAVED DATA FOR USER "..plr.UserId)
			plr.PlayerGui.Menu.Notif.PushNotif:FireAllClients("Data Saved!","Your data has been saved.")
		else
			print("SCOTWARE CORP. FAILED TO SAVE DATA FOR USER "..plr.UserId)
			plr.PlayerGui.Menu.Notif.PushNotif:FireAllClients("Error!","An error has occured and your data has not been saved.")
		end
		plr.PlayerGui.Menu.Notif.PushNotif:FireAllClients("UCS Payment","Your Universal Credit payment of £24 has been deposited.")
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	local success = xpcall(function()
		moneystore:SetAsync(plr.UserId,t.Value)
	end, warn)
	if success then
		print("SCOTWARE CORP. SAVED DATA FOR USER "..plr.UserId)
		plr.PlayerGui.Menu.Notif.PushNotif:FireAllClients("Data Saved!","Your data has been saved.")
	else
		print("SCOTWARE CORP. FAILED TO SAVE DATA FOR USER "..plr.UserId)
		plr.PlayerGui.Menu.Notif.PushNotif:FireAllClients("Error!","An error has occured and your data has not been saved.")
	end
end)

Why do you have this? This will set the players t.Value equal to the amount they have save, or if they dont have anything saved then it will be 63

If players are new to the game they start with 63 and not 0.
But did the 2 players have different amount of money in the game?
Because as far i can see everyone gets money at the same time.

far as i can see “t” is a global value and every time a player leaves you set their money to the value of “t” which does not change so that is probably the reason they have the same amount of money

t is an intvalue that’s cloned to the player, the variable is to the variable that is in the player

honestly your whole approach is just ugly and impractical, i would suggest using ProfileService

or datastore2 instead of making your own datastore and moving from there