Currently, I am making a Sword PvP Zone in my game.
local zone = script.Parent
local sword = game.ReplicatedStorage.Sword
local debounce = false
zone.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and debounce == false then
if not player.Backpack:FindFirstChild("Sword") and not hit.Parent:FindFirstChild("Sword") then
local clone = sword:Clone()
clone.Parent = player.Backpack
debounce = true
end
end
end)
zone.TouchEnded:Connect(function(no)
local player = game.Players:GetPlayerFromCharacter(no.Parent)
if player.Backpack:FindFirstChild("Sword") then
player.Backpack.Sword:Destroy()
else
local swordpos = no.Parent.Sword.Handle.Position
if swordpos.X < zone.Position.X - zone.Size.X/2 or swordpos.X > zone.Position.X + zone.Size.X/2 or swordpos.Z < zone.Position.Z - zone.Size.Z/2 or swordpos.Z > zone.Position.Z + zone.Size.Z/2 then
no.Parent.Sword:Destroy()
end
end
debounce = false
end)
This script doesn’t work. It gives you the sword when you enter it and removes the sword if you exit the zone, but if the sword is equipped it won’t remove your sword. How can I fix this?