Saved equipment when bought sometimes saves only to 1 server

So if i bought a weapon in my game it saves, but somtimes when i buy a weapon and change servers, the server that i bought the weapon on will have it, but the server i just joined wont?

is there a way i can prevent this with some sort of safety script?.
here is the short version with all the parts that link to the weapons.

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)

local playerData = Instance.new("Folder")
	playerData.Name = player.Name
	playerData.Parent = game.ServerStorage.PlayerData
	
	local equipped = Instance.new("StringValue")
	equipped.Name = "Equipped"
	equipped.Parent = playerData
	
	local inventory = Instance.new("Folder")
	inventory.Name = "Inventory"
	inventory.Parent = playerData

	local weaponsData
	local equippedData

local success, errormessage = pcall(function()
weaponsData = myDataStore:GetAsync(player.UserId.."-Weps")
equippedData = myDataStore:GetAsync(player.UserId.."-EquippedValue")
end)

pcall(function()
		weaponsData = myDataStore:GetAsync(player.UserId.."-Weps")
	end)
		
	pcall(function()
		equippedData = myDataStore:GetAsync(player.UserId.."-EquippedValue")
	end)

if weaponsData then
		for _, weapon in pairs(weaponsData) do -- {"Sword3","Sword2","Sword","Icegun"}
			if game.ServerStorage.Items:FindFirstChild(weapon) then
				local weaponClone = game.ServerStorage.Items[weapon]:Clone()
				weaponClone.Parent = inventory
				print(weapon.." loaded in!")
			end
		end
		
		if equippedData then -- No weps, no equips!
			equipped.Value = equippedData
			player:WaitForChild("PlayerGui")
			game.ReplicatedStorage.SendEquipped:FireClient(player,equippedData) -- Send the player's equipped item to the client to display as GUI
		end
		
	else print("No weapons data") end
		
end)

game.Players.PlayerRemoving:Connect(function(player)

pcall(function()
		local weapons = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
		local weaponsTable = {}
		for _, v in pairs(weapons) do
			table.insert(weaponsTable,v.Name)
		end
		myDataStore:SetAsync(player.UserId.."-Weps",weaponsTable)
		if game.ServerStorage.PlayerData[player.Name].Equipped.Value ~= nil then
			local equippedSaveValue = game.ServerStorage.PlayerData[player.Name].Equipped.Value
			myDataStore:SetAsync(player.UserId.."-EquippedValue",equippedSaveValue)
		end
	end)
	print("Saved weapons and points")
	bindableEvent:Fire()
	
	if success then
		print("Player Data successfully saved!")
	else
		print("There was an error when saving data")
		warn(errormessage)
	end

end)

It’s an issue with how you’re saving that you’ve bought a weapon. Without seeing your code, it’s impossible for us to help you.

If you want to save things in all servers you should use datastores. Kampfkarren has made a datastore module which makes it easier and more reliable to use datastores, you should check it out. Also, make sure to post your code so we can actually help you, there is a guideline in this thread.

You’re probably experiencing a throttle somewhere. Lack of code leaves your problem unable to be addressed. Please do include a relevant snippet of code so that we can better support you.

From the SetAsync page

Using GlobalDataStore/GetAsync to retrieve a value and then setting the key with SetAsync is dangerous because GlobalDataStore/GetAsync sometimes returns cached data, and other game servers may have modified the key.

So you should use UpdateAsync instead (but be sure to check that the key in the DataStore already exists because if it doesn’t, then you should use SetAsync)

I am trying to understand the difference between GlobalDataStore and DataStore.
Is GlobalDataStore for all servers and DataStore for the current server in use?
If so should we use GlobalDataStore as default?

There’s quite frankly no difference. DataStores inherit from GlobalDataStore. GlobalDataStore is the default DataStore, while DataStores allow you to partition data by allowing you to pass both two values to set up a dataspace; a name and a scope. A name is like a folder and scopes are like subfolders.

Both are used for games, not one over the other. You’ll hardly see yourself needing to use the GlobalDataStore unless the server needs to save a change that affects other servers in the future. Can’t quite think of any examples, though it’d probably be for things that aren’t related to standard data saving per player.

These are almost the same thing (but don’t point to the same DataStore):

local Data = DataStoreService:GetGlobalDataStore()
local Data = DataStoreService:GetDataStore("Global")

To note: the scope of DataStores default to global. Changing it essentially opens up a new folder.

local Data = DataStoreService:GetDataStore ("Global", "Not")

DataStores need a name, GlobalDataStore just points to a default.

- Global

- Data1

- Scope1