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

im using a part to give a linked sword but it keeps giving me a ton. is there a way to stop this?

It also needs to be able to get the sword again after it was taken from inventory because i also have a part that takes it.

local debounce = false
	 
	script.Parent.Touched:Connect(function(hit)
	    if not debounce then
	        debounce = true
	        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	        local LinkedSword = game.ServerStorage.ClassicSword:Clone()
	        LinkedSword.Parent = player.Backpack
	        wait(3)
	        debounce = false
	    end
	end)

3 answers

✓ Accepted answer

ANSWER: Your debounce is great! But you are checking for the opposite (if not debounce) of debounce which will always give you the else part of your if.

So instead try this:

local debounce = true
script.Parent.Touched:Connect(function(hit)
	if debounce then
		debounce = false
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local LinkedSword = game.ServerStorage.ClassicSword:Clone()
		LinkedSword.Parent = player.Backpack
		wait(3)
		debounce = true
	end
end)

1 comment

1

thank you!!

Do this!




local sword = game.ServerStorage:WaitForChild("ClassicSword")
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Sword2Find = hit.Parent:FindFirstChild("ClassicSword")
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local OtherSword2Find = player.Backpack:FindFirstChild("ClassicSword")
		if not Sword2Find and not OtherSword2Find then
			sword:Clone()
			sword.Parent = hit.Parent
		end
	end
end)


script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if hit.Parent:FindFirstChild("ClassicSword") or player:FindFirstChild("ClassicSword") then
		else
			local LinkedSword = game.ServerStorage.ClassicSword:Clone()
			LinkedSword.Parent = player.Backpack
		end
	end
end)

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