✓ Accepted answer
First off, let's fix the indentation and replace findFirstChild with FindFirstChild, and connect with Connect, because those two functions are deprecated(or at least I think they are):
function onEquipped(e)
if e.Parent ~= nil then
if e.Parent:FindFirstChild("ForceField") ~= nil then
e.Parent.ForceField:remove()
end
end
end
script.Parent.Equipped:Connect(onEquipped)
Secondly, the Equipped event of the tool instance doesn't return the character of the player that has the tool. As a matter of fact, the tool is parented to the character of the player that equipped it, when it is equipped.
So, we know that when the player equips the tool, we can access their character by doing this:
local tool = script.Parent
function onEquipped()
local forceField = tool.Parent:FindFirstChild("ForceField")
if (forceField) then
forceField:Destroy()
end
end
tool.Equipped:Connect(onEquipped)
This'll destroy a ForceField, if it is found in the character.
2 comments
Shouldn't it be tool.Parent:FindFirstChild("ForceField")? There isnt any ForceField inside the tool but its in the character
Right, I have no clue why I put that.