Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Remove when Pike Pole touches glass?

Asked by
cop346 5
9 years ago

I'm trying to make a script where if the Pike Pole touches the part it removes.

But I have multiple of them in the game. So I don't want all the parts named "Glass" to remove

local part = script.Parent
part.Touched:connect(function(hit)
    if hit.Parent then
        local pike = hit.Parent:FindFirstChild("Pike Pole")
        if pike then
            script.Parent.Glass:remove()
        end
    end
end)


it worked when I did game.Workspace.Glass:remove()

though

0
Is this script in the glass? Sublimus 992 — 9y
0
yes cop346 5 — 9y

1 answer

Log in to vote
1
Answered by
Sublimus 992 Moderation Voter
9 years ago

You are trying to find a object named glass inside of the glass part, so it'll never work.

local part = script.Parent -- The glass
part.Touched:connect(function(hit)
    if hit.Parent then
        local pike = hit.Parent:FindFirstChild("Pike Pole")
        if pike then
            part:Destroy() -- Kill glass
        end
    end
end)
0
That worked! Thank you. cop346 5 — 9y
0
No problem. Sublimus 992 — 9y
Ad

Answer this question