I made a script that Gives a sword when you enter an area (touch the part that fills the whole area) and remove it when you arent touching anymore and it seems to be giving me another sword once I select the sword. And when I leave the area only 1 sword gets removed leaving players with another weapon in an area where there shouldnt be a weapon.
local IsTouching = false script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild('Humanoid') local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if hum and not IsTouching then IsTouching = true game.ReplicatedStorage.Sword:clone().Parent = plr.Backpack end end) script.Parent.TouchEnded:Connect(function(hit) local hum = hit.Parent:FindFirstChild('Humanoid') local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if hum and IsTouching then IsTouching = false plr.Backpack.Sword:Destroy() end end)
That's because you are only checking for the sword in the player's backpack. When he equips the sword, it gets put inside the player's character.