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)

1 comment
The conditional is not reliant on the sword at all actually because all it checks for is the humanoid and the bool, however, that is also true.