Best way to give tools

I was trying to make a simple script so when a player touches a part they are given a tool. Everything worked well except that a single player could get tons of tools.

So what you want is that a player doesn’t get’s tool twice?
Provide code please

If you don’t want the player to get lots of tools a lot of times in such speed then you could use debounces
but if you don’t want the player to get the tool twice you can verify if the player already has it in his backpack

1 Like

yes sorry for not posting code here it is:

local taco = game.ReplicatedStorage.Taco

script.Parent.Touched:Connect(function(plr)
local hum = plr.Parent:FindFirstChildWhichIsA(“Humanoid”)
if hum then
local tacoclone = taco:Clone()
tacoclone.Parent = hum.Parent
end
end)

local taco = game.ReplicatedStorage.Taco

script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
if (p.Backpack:FindFirstChild('Taco')) then
return
end
local tacoclone = taco:Clone()
tacoclone.Parent = p.Backpack
end
end)

Gope it helps! :slight_smile:

tried it and got an error [ Workspace.TacoStand.TacoTouch.TacoTouch:6: Expected ‘)’ (to close ‘(’ at column 4), got ‘then’]

local taco = game.ReplicatedStorage.Taco

script.Parent.Touched:Connect(function(plr)
    local hum = plr.Parent:FindFirstChildWhichIsA(“Humanoid”)
    
    if hum then
        local LocalPlayer = game.Players:GetPlayerFromCharacter(plr.Parent)
        if LocalPlayer ~= nil then
            if not LocalPlayer.Backpack:FindFirstChild("Taco") or not plr.Parent:FindFirstChild("Taco") then
                local tacoclone = taco:Clone()
                tacoclone.Parent = hum.Parent
            end
        end
    end
end)

this did not work and gave the exact same results as the script I had before

Try this;

local taco = game.ReplicatedStorage.Taco

script.Parent.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
if (p.Backpack:FindFirstChild('Taco')) then
return
end
local tacoclone = taco:Clone()
tacoclone.Parent = p.Backpack
end
end)

This almost worked but it gave me two tacos which was weird

local taco = game.ReplicatedStorage.Taco

script.Parent.Touched:Connect(function(plr)
    local hum = plr.Parent:FindFirstChildWhichIsA("Humanoid")
    
    if hum then
		local LocalPlayer = game.Players:GetPlayerFromCharacter(plr.Parent)
		
        if LocalPlayer ~= nil then
			if not LocalPlayer.Backpack:FindFirstChild("Taco") then
				if not plr.Parent:FindFirstChild("Taco") then
                	local tacoclone = taco:Clone()
					tacoclone.Parent = hum.Parent
				end
            end
        end
    end
end)
1 Like

Jusy for reference when you encounter multiple result on the connect event next time, you might need to use debounce