Still have questions? Join our Discord server and get real time help.
0

# How do I make a part turn CanCollide=true if a certain model is destroyed?

s9i -5
1 year ago

I'm new to scripting and trying to figure out how I would do this...I'm trying to turn part FakeDoor's CanCollide to true when model ElevatorDoor is destroyed. I've tried this:

game.Workspace.ElevatorDoor:Destroy()
if true then
game.Workspace.Elevator.FakeDoor:CanCollide = true
end

end


I'm sure it's horribly wrong, so I need some help.

3
RayCurse 1348
1 year ago
Edited 1 year ago

First you need to detect when the ElevatorDoor is destroyed. This can be done like this:

game.Workspace.ChildRemoved:Connect(function(obj)
if obj.Name == "ElevatorDoor" then
--ElevatorDoor was destroyed
end
end)


The first line is an event that fires when something in the workspace is destroyed. This event returns the object that was destroyed which is why the obj was put in the parentheses.

The event returns the obj that was destroyed. We need to check that the item that was destroyed was the elevator door and not just any object. That is what the if statement is for. Ok, let's add a little more to our previous code:

game.Workspace.ChildRemoved:Connect(function(obj)
if obj.Name == "ElevatorDoor" then
--ElevatorDoor was destroyed
game.Workspace.Elevator.FakeDoor.CanCollide = true
end
end)


So basically, translated to english this is what it says:

When something inside the workspace is destroyed,

If the thing that was destroyed is the elevator door,

Set the collision of the fake door to true

end

end

Hope this helps!

0
Thank you very much! s9i -5 — 1y
0
game.Workspace.ElevatorDoor:Destroy()