Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make this script detect a player if they already have the tool?

I have this script, but it will give the same player the tool they already have after 0.5 seconds, how do I make it so that the script can detect a player who already has a tool so that way it doesn't give them the tool again?

local debounce = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Humanoid then
        if debounce == true then return end
        debounce = true
        plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        local gravity = game.ReplicatedStorage.ClassicSword:Clone()
        gravity.Parent = plr.Backpack
        wait(0.5)
        debounce = false
    end
end)

2 comments

0

i cant give advice but not an answer, maybe try making a variable like got = game.StarterPack.toolname and then getting it to run an else if?

0

Check to see if the tool exists using if backpack:FindFirstChild(toolname) then

1 answer

local debounce = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Humanoid then
        if debounce == true then return end
        debounce = true
        plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local foundTool = plr.Backpack:FindFirstChild("ClassicSword") or plr.Character:FindFirstChild("ClassicSword")
		if not foundTool then
			local gravity = game.ReplicatedStorage.ClassicSword:Clone()
    	    gravity.Parent = plr.Backpack
		end
        wait(0.5)
        debounce = false
    end
end)

2 comments

0

Thanks for the help matt.

0

If it worked accepting the answer would be much appreciated (:

This discussion is preserved as it was. New answers, comments, and votes are closed.