Custom tool pickup and RemoteEvent Latency

Howdy howdy howdy! I’m in the middle of debugging some features in my new game. An issue I came across are tools being duplicated when two players click the same item at the same time. I thought this would be an easy fix considering I can just have the server check if the part is still there and it would automatically deny the second player. I was unable to find a way to prevent this. Does anyone have any insight for me?

function Equip(Player,Character,Cargo) --The Server script.
	if Cargo then
		local Tool = ReplicatedStorage.ToolStorage[Cargo.Name]:Clone()
		Tool.Parent = workspace
		Cargo:Destroy()
		if Character then
			Character.Humanoid:EquipTool(Tool)
		end
	end
end

EquipCargoRemote.OnServerEvent:Connect(Equip)

--End of Server script.


local ReplicatedStorage = game:GetService('ReplicatedStorage') --Localscript
local EquipCargoRemote = ReplicatedStorage.EquipCargoRemote

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

function Button1Down()
	local Character = Player.Character
	if not (Character.Humanoid:GetState() == Enum.HumanoidStateType.Dead) then
		local Cargo = Mouse.Target
		if Cargo then
			local Tool = Character:FindFirstChildWhichIsA('Tool')
			if (Cargo.Name == 'Common Cargo') or (Cargo.Name == 'Rare Cargo') then
				if Player:DistanceFromCharacter(Cargo.Position) < 12 then
					if not Tool then
						EquipCargoRemote:FireServer(Character,Cargo)
					end
				end
			end
		end
	end
end

Mouse.Button1Down:Connect(Button1Down)

Thank you!

1 Like

You could use a debounce on the server side to ensure that this doesn’t happen.
I’d also check the Distance on the server, exploiters could just fire this RemoteEvent and wherever they are would get the cargo.