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

How to make part break when a specific object touches it?

Asked by 6 years ago

This glass breaking script only breaks when any object touches it, because it is onTouch. How ever how would i make it were a specific object touches it that is located in the workspace, like the baseplate?

function x(hit)
script.Parent.Anchored = false
script.Parent.GlassSound:Play()
script:remove()
end

script.Parent.Touched:connect(x)

1 answer

Log in to vote
0
Answered by
xEiffel 280 Moderation Voter
6 years ago

You can use .Name in an if statement inside of the ("hit")

function x(hit)
if hit.Name == "Baseplate" then
script.Parent.Anchored = false
script.Parent.GlassSound:Play()
script:remove()
end
end

script.Parent.Touched:connect(x)

This would make it so that if the name of the part that is touching the glass is "Baseplate", the glass will break. You can also do methods for players using a statement to figure out if they have a humanoid inside them,

function x(hit)
if hit.Parent:FindFirstChild("Humanoid") then
script.Parent.Anchored = false
script.Parent.GlassSound:Play()
script:remove()
end
end

script.Parent.Touched:connect(x)

Hope this helps!

0
Wow thank you, this is helped alot. Carforlife1 59 — 6y
Ad

Answer this question