Coins keep on multiplying by 2

You can write your topic however you want, but you need to answer these questions:

For the Coin and Tool shop system in my (Watched from a @Alvin_Blox tutorial). The Data saving is all messed up, what keeps on happening is that, everytime I leave and rejoin a team test session my coins double by 2. Also, sometimes it just adds a random sword into my inventory. This is used with DataStore 1 and I’m not sure if DataStore 1 itself is broken, or if there is a script or a model doing this.

I’ve resetted the data for players too see if this will fix it but it hasn’t

Could you attach the script. We don’t know how the script looks as it is now.

Okay, So I was able to figure out why the Coins where multiplying by 2, it was due to my 2x gamepass. Now I just need too find out why my tools keep messing up

Here is the script, I’ve already solved the problem with the Coins, it’s just the tool saving messing up

local DataStore = game:GetService("DataStoreService"):GetDataStore("MyDataStore")



game.Players.PlayerAdded:Connect(function(plr)
	
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	 	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	
	local data
	local coinStored
	
	local success, errorMessage = pcall(function()
		data = DataStore:GetAsync(plr.UserId.."MyTools")
		coinStored = DataStore:GetAsync(plr.UserId.."MyCoins")
	end)
	if coinStored ~= nil then
		coins.Value = coinStored
		print("data saved")
	else
		coins.Value = 0
		print("data broke")
	end
	
	if data ~= nil then
		for _, toolName in pairs(data) do
			
			local tool =game.ReplicatedStorage.Swords:FindFirstChild(toolName)
			
			if tool then
				local newTool = tool:Clone()
				newTool.Parent = plr.Backpack
				
				local newTool = tool:Clone()
				newTool.Parent = plr.StarterGear
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	
	local toolsTable = {}
	
	for _, tool in pairs(plr.Backpack:GetChildren()) do
		if game.ReplicatedStorage.Swords:FindFirstChild(tool.Name) then
			table.insert(toolsTable,tool.Name)
		end
	end
	
	local success, errorMessage = pcall(function()
		DataStore:SetAsync(plr.UserId.."MyTools",toolsTable)
		DataStore:SetAsync(plr.UserId.."MyCoins",plr.leaderstats.Coins.Value)
	end)
	
end)

game:BindToClose(function()
	for _, plr in pairs(game.Players:GetPlayers()) do
		local toolsTable = {}
		
		for _, tool in pairs(plr.Backpack:GetChildren()) do
			if game.ReplicatedStorage.Swords:FindFirstChild(tool.Name) then
				table.insert(toolsTable,tool.Name)
			end
		end
		
		local success, errorMessage = pcall(function()
			DataStore:SetAsync(plr.UserId,toolsTable)
		end)
	
	end
end)

I don’t know what the real issue is, but a quick fix is:

-- Inside the PlayerAdded function
coins.Value = coinStored/2

or

-- Inside the PlayerRemoving function
DataStore:SetAsync(plr.UserId.."MyCoins",plr.leaderstats.Coins.Value/2)

Either one works, but both of them will divide your coins by 2.
Other then that I don’t know what the real issue is.

I’ve already solved the coins problem. It was just the tool saving.