Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

1 comment

0

Wow thank you, this is helped alot.

This discussion is preserved as it was. New answers, comments, and votes are closed.