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

Debounce for on touched event not working??

Not sure what's going on here but it could just be me being dumb, my debounce isn't working. other than that everything is working fine

is it because of how I placed the debounce?

game.Players.PlayerAdded:Connect(function(player)
	script.Parent.Touched:Connect(function(hit)

		local char = hit.Parent
		local hum = char:FindFirstChild("Humanoid")

		local debounce = false

		if hum and not debounce then


			local players = game:GetService("Players")
			local player = players:GetPlayerFromCharacter(char)
			local pack = player.Backpack
			local findSword = pack:FindFirstChild(player.Name.."'s sword")
			local char = player.Character or player.CharacterAdded:Wait()
			local equippedSword = char:FindFirstChild(player.Name.."'s sword")
			if not findSword  and not equippedSword then  


				local SwordE = player:WaitForChild("EquippedSword")
				if SwordE then
					local Swordbank = game.ReplicatedStorage:WaitForChild("SWORDBANK")
					for _,Bank in pairs(Swordbank:GetChildren()) do
						if Bank:IsA("Tool") then
							if Bank.Name == SwordE.Value then


								local CloneBank = Bank:Clone()
								CloneBank.Name = (player.Name.."'s sword")
								CloneBank.Parent = char


								debounce = true
								wait(5)
								debounce = false

							end
						end	
					end
				end
			end
		end
	end)
end)

1 answer

✓ Accepted answer

Yes, it IS because of how the debounce is placed. debounce is always set to false when the event fires. You need to declare the variable outside the events.

1 comment

0

Ohh i see, alright thanks a ton

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