Data being shared between multiple people

So I have this scavenger hunt game where you find Pots. Your objective is to get them all. However, there’s an issue, and that being that when someone collects a Pot, another player gets it for some reason. This has never happened before, and the game has been up for probably a year by now. What could possibly be the issue?

Local script for collecting pots:

wait(1)
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local Pots = game.Workspace:WaitForChild("Pots")
local BadgeService = game:GetService("BadgeService")

local player = game.Players.LocalPlayer
local userid = player.UserId
local CollectedData
game.ReplicatedStorage.AskForCollected:FireServer()
game.ReplicatedStorage.SendOutData.OnClientEvent:Connect(function(data)
	if data ~= nil then
		CollectedData = data
	end
end)
debounce = false

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			if hit.Parent == workspace.Pots and debounce == false then
				debounce = true
				
				game.ReplicatedStorage.AskForCollected:FireServer()
				game.ReplicatedStorage.SendOutData.OnClientEvent:Wait(function(data)
					if data ~= nil then
						CollectedData = data
					end
				end)
				
				local plr = game.Players.LocalPlayer
				local human = script.Parent:WaitForChild("Humanoid")
				local GUI = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("CollectGui").Text
				local badge = hit.BadgeID.Value
				
				if CollectedData[hit.Name].Collected == true then
					game.StarterGui:SetCore("SendNotification", {
						Title = "Already found",
						Text = "You already found "..hit.Name,
						Icon = hit.Decal.Texture
					})
					game.ReplicatedStorage.GiveBadge:FireServer(badge)
					wait(1)
					debounce = false
				else
					if hit.Difficulty.Value == "Very Easy" then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = -30
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(179, 255, 165)
					elseif hit.Difficulty.Value == "Easy"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = -20
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(0, 180, 0)
					elseif hit.Difficulty.Value == "Medium"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = -10
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(255, 255, 0)
					elseif hit.Difficulty.Value == "Hard"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = 0
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(255, 0, 0)
					elseif hit.Difficulty.Value == "Rough"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = 10
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(131, 128, 144)
					elseif hit.Difficulty.Value == "Insane"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = 20
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(0, 22, 255)
					elseif hit.Difficulty.Value == "EXTREME"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = 30
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(0, 161, 254)
					elseif hit.Difficulty.Value == "HORRIBLE"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = 40
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(0, 243, 255)
					elseif hit.Difficulty.Value == "U̴̯̦͐̽Ň̸̩̕H̸̪̳̮́Ȩ̴͒̍A̵̫̋̂̍͜V̸̨̢̺̇È̸̦͔̞̓̌Ń̵̮̭̅L̶͉̐̚Y̷̛͇͐͌"  then
						GUI.Parent.Difficulty.Text = hit.Difficulty.Value
						GUI.LayoutOrder = 50
						GUI.Parent.Difficulty.TextColor3 = Color3.fromRGB(130, 7, 0)
					end

					game.ReplicatedStorage.SendInCollected:FireServer(hit.Name)
					game.Workspace.CollectBadgeID.Value = badge
					game.ReplicatedStorage.Badge:FireServer(badge, hit.Name)
					game.StarterGui:SetCore("SendNotification", {
						Title = hit.Name,
						Text = "Nice, you found "..hit.Name,
						Icon = hit.Decal.Texture,
					})
					
					game.ReplicatedStorage.AskForCollected:FireServer()
					game.ReplicatedStorage.SendOutData.OnClientEvent:Wait(function(data)
						if data ~= nil then
							CollectedData = data
						end
					end)
					
					wait(1)
					debounce = false
				end
			end
		end)
	end
end

Server script for data saving and other fun doohickeys:

local ds = game:GetService("DataStoreService"):GetDataStore("PlayerDataNQ3")

_G.PlayerData = {}
game.Players.PlayerAdded:Connect(function(plr)
	_G.PlayerData[plr.UserId] = {
		Collected = {
			["1,000 Visits Pot"] = {
				Collected = false
			},
			["AWOOGA"] = {
				Collected = false
			},
			["Badly Made Pot"] = {
				Collected = false
			},
			["Banned Pot"] = {
				Collected = false
			},
			["Broken Pot"] = {
				Collected = false
			},
			["Burning Pot"] = {
				Collected = false
			},
			["Candy Corn Pot"] = {
				Collected = false
			},
			["Candy King Pot"] = {
				Collected = false
			},
			["Cartoon Pot"] = {
				Collected = false
			},
			["Chalkboard Pot"] = {
				Collected = false
			},
			["Cheese Pot"] = {
				Collected = false
			},
			["Coin Pot"] = {
				Collected = false
			},
			["Cookie Pot"] = {
				Collected = false
			},
			["Dancing Pot"] = {
				Collected = false
			},
			["Dialogue Pot"] = {
				Collected = false
			},
			["Donut Pot"] = {
				Collected = false
			},
			["Driving Pot"] = {
				Collected = false
			},
			["Encoded Pot"] = {
				Collected = false
			},
			["Falling Pot"] = {
				Collected = false
			},
			["Farmer Pot"] = {
				Collected = false
			},
			["Flame Pot"] = {
				Collected = false
			},
			["Flappy Pot"] = {
				Collected = false
			},
			["Flower Pot"] = {
				Collected = false
			},
			["Gamer Pot"] = {
				Collected = false
			},
			["Gem Pot"] = {
				Collected = false
			},
			["Gingerbread Pot"] = {
				Collected = false
			},
			["Graffiti Pot"] = {
				Collected = false
			},
			["Grassy Pot"] = {
				Collected = false
			},
			["Guard Pot"] = {
				Collected = false
			},
			["Happy Home Pot"] = {
				Collected = false
			},
			["Hay Pot"] = {
				Collected = false
			},
			["Hot Chocolate Pot"] = {
				Collected = false
			},
			["Hyper Secret Pot"] = {
				Collected = false
			},
			["Ice Cream Pot"] = {
				Collected = false
			},
			["Juice Pot"] = {
				Collected = false
			},
			["Lava Pot"] = {
				Collected = false
			},
			["Lollipop Pot"] = {
				Collected = false
			},
			["Magma Pot"] = {
				Collected = false
			},
			["Marshmallow Pot"] = {
				Collected = false
			},
			["Melted Pot"] = {
				Collected = false
			},
			["Miner Pot"] = {
				Collected = false
			},
			["Nerd Pot"] = {
				Collected = false
			},
			["Neon Pot"] = {
				Collected = false
			},
			["Noob Pot"] = {
				Collected = false
			},
			["Normal Pot"] = {
				Collected = false
			},
			["Obby Pot"] = {
				Collected = false
			},
			["Orange Pot"] = {
				Collected = false
			},
			["Paint Splattered Pot"] = {
				Collected = false
			},
			["Pig Pot"] = {
				Collected = false
			},
			["Pixelated Pot"] = {
				Collected = false
			},
			["Plushie Pot"] = {
				Collected = false
			},
			["Pot JR."] = {
				Collected = false
			},
			["Pot That Has Hippopotomonstrososesquippedaliophobia"] = {
				Collected = false
			},
			["Potbux"] = {
				Collected = false
			},
			["Pro Pot"] = {
				Collected = false
			},
			["Rainbow Secret Pot"] = {
				Collected = false
			},
			["Realistic Pot"] = {
				Collected = false
			},
			["Red Pot"] = {
				Collected = false
			},
			["Reset Pot"] = {
				Collected = false
			},
			["Rest In Potses"] = {
				Collected = false
			},
			["Rich Pot"] = {
				Collected = false
			},
			["Ruler Pot"] = {
				Collected = false
			},
			["Scribble Pot"] = {
				Collected = false
			},
			["Secret Pot"] = {
				Collected = false
			},
			["Shiny Pot"] = {
				Collected = false
			},
			["Stopping Pot"] = {
				Collected = false
			},
			["Stud Pot"] = {
				Collected = false
			},
			["Super Secret Pot"] = {
				Collected = false
			},
			["Template Pot"] = {
				Collected = false
			},
			["Ticket Pot"] = {
				Collected = false
			},
			["Traveling Pot"] = {
				Collected = false
			},
			["Un-Secret Pot"] = {
				Collected = false
			},
			["White Pot"] = {
				Collected = false
			},
			["Yellow Pot"] = {
				Collected = false
			},
			["Zombpot"] = {
				Collected = false
			},
			["Picnic Pot"] = {
				Collected = false
			},
			["Chilling Pot"] = {
				Collected = false
			},
			["Ant Pot"] = {
				Collected = false
			},
			["Wish Pot"] = {
				Collected = false
			},
			["Water Pot"] = {
				Collected = false
			},
			["poot"] = {
				Collected = false
			},
			["Dreadful Pot"] = {
				Collected = false
			},
			["Shattered Pot"] = {
				Collected = false
			},
			["potsjal"] = {
				Collected = false
			},
			["Super Ultra Miniature Nonexistent Tiny Pot"] = {
				Collected = false
			},
			["Blarret Pot"] = {
				Collected = false
			},
			["Sunburnt Pot"] = {
				Collected = false
			},
			["Coral Pot"] = {
				Collected = false
			},
			["Fish Pot"] = {
				Collected = false
			},
			["Swimming Pot"] = {
				Collected = false
			},
			["Cybernetic Pot"] = {
				Collected = false
			},
			["Dementia Pot"] = {
				Collected = false
			},
			["All-Seeing Pot"] = {
				Collected = false
			},
			["Star Pot"] = {
				Collected = false
			},
			["Voidstruck Pot"] = {
				Collected = false
			},
			["Inverted Pot"] = {
				Collected = false
			},
		}
	}
	local data = _G.PlayerData[plr.UserId]
	local save = ds:GetAsync(plr.UserId)
	if save then		
		for i, v in pairs(save.Collected) do
			if data.Collected[i] then
				
			else
				data.Collected[i] = {
					Collected = false
				}
			end
		end
		for i, v in pairs(data.Collected) do
			if save.Collected[i] then
				
			else
				save.Collected[i] = {
					Collected = false
				}
			end
		end

 		for i,v in pairs(save.Collected) do
			data.Collected[i] = v
		end
	end
end)

game.ReplicatedStorage.AskForCollected.OnServerEvent:Connect(function(player)
	local CollectedTable = _G.PlayerData[player.UserId].Collected
	game.ReplicatedStorage.SendOutData:FireClient(player, CollectedTable)
end)

game.ReplicatedStorage.SendInCollected.OnServerEvent:Connect(function(player, pot)
	_G.PlayerData[player.UserId].Collected[pot].Collected = true
	print(player.UserId)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local save = ds:GetAsync(plr.UserId)
	if save ~= _G.PlayerData[plr.UserId] then
		ds:SetAsync(plr.UserId,_G.PlayerData[plr.UserId])
	end
	_G.PlayerData[plr.UserId] = nil
end)

game:BindToClose(function()
	for i, plr in pairs(game.Players:GetChildren()) do
		local save = ds:GetAsync(plr.UserId)
		if save ~= _G.PlayerData[plr.UserId] then
			ds:SetAsync(plr.UserId,_G.PlayerData[plr.UserId])
		end
		_G.PlayerData[plr.UserId] = nil
	end
end)

I’m looking for solutions to simply just THIS. I do not wish for any other things that don’t relate to my issue.

in the v.Touched:Connect function you arent checking for if the player touching the part is the local player

all youd have to do is just add a check like:

local Players = game:GetService("Players");
local LocalPlayer = Players.LocalPlayer;

Part.Touched:Connect(function(Hit: BasePart)
     local Character = Hit.Parent;
     local Player = Players:GetPlayerFromCharacter(Character);

     if Player == LocalPlayer then
           -- code here
     end
end);

i think that should be an automatic though. The script is in the character.

no, your checking for a .Touched event on the part itself, which means when the part gets touched, it fires the function

it doesnt matter what script runs it, or where it is, the .Touched event is the same no matter what

Adding a check won’t change anything. The script cycles through all the character’s body parts and adds a :Touched() function to it. If it detects that what touched it is in workspace.Pots, then it proceeds. I don’t see why I need to add a check to see if its the player when the function is for the player. Voidymite’s code implies that hit.Parent would be the character, when hit.Parent is actually workspace.Pots, and the character is running the .Touched() function.

oh, i used context clues from replies rather than reading the entire script, sorry for that
as for the issue, can you check what _G.PlayerData[plr.UserId] is equal to when multiple people are in the server? and then check if that table changes when another player collects a pot

send your results so i can take a look at them once your done, please!

i skimmed through and assumed it was part of a folder with the pots in it, my bad (although i think that would be a better method)

I’m sorry to have bothered you with this. It’s not doing it anymore. I genuinely don’t know what’s up with it. I tested it with my alt, and, all of a sudden, my alt could collect the Pots just fine. :sweat:
I don’t know if I should keep this thing open or just close it right here, for the risk of it happening again.
Anyways, the table returned as two different things for two different players. They weren’t the same.
In short, because the tables are long, I won’t include every Pot, just 5/96.
My table:

Normal Pot = true
Farmer Pot = true
Pig Pot = true
Chilling Pot = true
Picnic Pot = false
}

My alt’s table:

Normal Pot = true
Farmer Pot = false
Pig Pot = false
Chilling Pot = false
Picnic Pot = true
}

did the bug happen in studio or on platform? studios behavior can be a little questionable at times and does not represent an exact copy of what you would see on the platform

The platform.

aaaaaaaaaaaaaaaa

thats odd

i would just close this topic for now, if it happens again you might need to think of a new way to handle player data