I have a script inside a part intended to remove an item from a player on a certain team, and give them a force field. However, if the player is holding the gun then the item cannot be removed from their inventory. How can I fix this?
local debounce = false
function onTouched(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then
if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == script.Parent.BrickColor then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if debounce == false then
debounce = true
local c = Instance.new("ForceField")
c.Parent = hit.Parent
if Player.Backpack.Gun == Player.Backpack.Gun then
Player.Backpack.Gun:Remove()
print("Gun Removed From BackPack")
wait(.1)
debounce = false
else if Player.Character.Gun == Player.Character.Gun then
Player.Character.Gun:Remove()
print("Gun Unequiped")
wait(.1)
debounce = false
end
end
end
end
end
end
script.Parent.Touched:connect(onTouched)

1 comment
this would work but I need it to only work for the bright red team.