So I want to make it when a player passes through a part(it’ll have CanCollide off and transparency to 1), they will get a sword. When they go through the part again, the sword will be removed. I have made it and it works, but it only works once. I think it’s because of the debounce since I tried removing it and it would remove and give you the sword continuously. So how do I fix this?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local debounce = false
local seconds = 1
local Sword = ReplicatedStorage:WaitForChild("ClassicSword") -- put the name of the sword here
local Part = script.Parent
Part.Touched:Connect(function(hit)-- 'hit' is what touched the Part
if not debounce then
debounce = true
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then -- if humanoid exists
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player.Backpack:FindFirstChild("ClassicSword") or player.Character:FindFirstChild("ClassicSword") then -- if sword exists in the backpack or is already equipped
player.Character:WaitForChild("Humanoid"):UnequipTools() -- unequips any tool
player.Backpack:FindFirstChild("ClassicSword"):Destroy() -- removes the sword
else -- if sword is not in the backpack or if the sword isnt equipped
Sword:Clone().Parent = player.Backpack -- clones and places the sword in the backpack
wait(seconds)
debounce = false
end
end
end
end
end)