So, I’m using @sleitnick 's Plane System that he had uploaded to the toolbox, and I’m wondering how would I be able to killed more than 1 seat’s occupant. In the original script, It only kills the pilot. I’ve added 3 more seats, and I’m wondering how it’d work
The line of code circled in red is how the script looked before. I added the lines of code where I’ve listed in red the 3 more seats, and It doesn’t work. It kills the pilot, but not the other players.
When the plane crashes, the Pilot dies but the other players on the plane stay alive and just fall off. When I just added Seat1.Occupant.Health = 0 inside of the Pilot if statement, the plane suddenly got god mode and it flew away on fire.
Sorry if this isn’t very filled with information, I don’t know what’s going on. I’ve tried to fix it and it doesn’t seem to work. Anyways, thank you for reading!
The reason nobody else is being killed, is because you are using elseif.
I’ll give an example bellow to help you better understand:
if Something == true then
-- Will run if Something is true
elseif Something2 == true then
-- Will only run if Something is false and Something2 is true
elseif Something3 == true then
-- Will only run if Something & Something2 are false and Something3 is true
end
To fix this issue, you should replace your elseif statements with if statements.
Hoped this helped you better understand!
for _, seat in ipairs(plane:GetDescendants()) do
if seat:IsA"Seat" or seat:IsA"VehicleSeat" then
if seat.Occupant then
seat.Occupant:TakeDamage(seat.Occupant.Health)
end
end
end
A loop would be the better alternative, especially if you intend to add more seats.