How to make players grab an item one at a time when a touched event gets triggered

So i really wanted to know how to make players grab an item one at a time but i got to the point where a players get all the same item at once like the video shown below:

My script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage:WaitForChild("OverseerSword")

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
   if player then
   	player.Team = game:GetService("Teams"):FindFirstChild("Green")
   	local cloneSword = Sword:Clone()
   	cloneSword.Parent = player.Character
   end
end)
1 Like

Ok that’s fine but nice :grinning::+1::+1::+1::+1::slightly_smiling_face::slightly_smiling_face:

1 Like

just check if the player already has the item and give it if he doesnt

1 Like

You need to add a debounce to the touched event.

1 Like

You could check if there’s already an item in the player’s inventory/character:

if not player.Character:FindFirstChild(Sword.Name) or not player:FindFirstChild("Backpack"):FindFirstChild(Sword.Name) then
    --Clone sword
end

I hope this helps you.

1 Like

It still does the same thing no changes

Try this:

if not (player.Character:FindFirstChild(Sword.Name) or player:FindFirstChild("Backpack"):FindFirstChild(Sword.Name)) then
    --Clone sword
end

I tested it and works :+1:.

2 Likes
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage:WaitForChild("OverseerSword")

script.Parent.Touched:Connect(function(hit)
	 local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		player.Team = game:GetService("Teams"):FindFirstChild("Green")

		
	
		if not (player.Character:FindFirstChild(Sword.Name) or player:FindFirstChild("Backpack"):FindFirstChild(Sword.Name)) then
			    --Clone sword
			local cloneSword = Sword:Clone()
			cloneSword.Parent = player.Character
		end
	end
end)

did I do that correctly?

1 Like

Yes, you did it correctly, that’s how it should look :+1:.

2 Likes

Just curious is this a proper way of using debounce if yes then why isn’t the script working?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage:WaitForChild("OverseerSword")
local debounce = false
script.Parent.Touched:Connect(function(hit)
	
	 local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		player.Team = game:GetService("Teams"):FindFirstChild("Green")		
		if not debounce then
			debounce = true
			wait(1)
			local cloneSword = Sword:Clone()
			cloneSword = player.Character
			
			debounce = false
		end
	end
end)

Kinda wanna know when to use debounce or not

I’ve tried your code and it works but i wanna know when to use debounce

1 Like

I think it’s better to create a new thread with more information for your issue, so we can help you in a better way :+1:.