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

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

Asked by
s9i 2
7 years 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:

1game.Workspace.ElevatorDoor:Destroy()
2     if true then
3         game.Workspace.Elevator.FakeDoor:CanCollide = true
4        end
5 
6end

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

2 answers

Log in to vote
3
Answered by
RayCurse 1518 Moderation Voter
7 years ago
Edited 7 years ago

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

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

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:

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

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 2 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

this may not work but

1game.Workspace.ElevatorDoor:Destroy()
2if game.Workspace.ElevatorDoor:Remove() then
3game.Workspace.ElevatorDoor.CanCollide = true
4end
0
Didn't work :(. I forgot to mention that the FakeDoor part is included in a model called "Elevator," and the script is functioning from an on touch button. s9i 2 — 7y

Answer this question