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

How to make the car delete when the driver leaves the game?

Asked by 4 years ago
Edited 4 years ago

I tried making the car delete when the driver leaves the game, but the car deletes also when a passenger leaves. I tried fixing this many times, but it didn't work out. If you have any solutions, that would be great.

game.Players.PlayerRemoving:Connect(function()
    script.Parent.Parent:Destroy()
end)
0
Keep track of the driver of the car somehow. The driver of the car could be whoever is in the drivers seat (the drivers seat occupant property will let you see whos sitting in the seat.) Once you have that done, check if the player leaving the game is the player in the seat: https://pastebin.com/sAprYPE8 royaltoe 5144 — 4y
0
the code: YOUR_DRIVERS_SEAT:GetPropertyChangedSignal("Occupant"):Connect(function() print("driver changed") end) will fire whenever someone leaves or sits on a seat. This is one way you can keep track of whos driving the car royaltoe 5144 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

So, basically you need to be a little more specific about which player is leaving the game and which one isn't. Here you'll be able to see what I am going to do:

game.Players.PlayerRemoving:Connect(function(p)
   Seat.Touched:Connect(function(hit)
   if hit.Parent.Name == p.Name then
   script.Parent.Parent:Destroy()
   end
   end)
end)

This may or may not work, because I am not in Team Create mode to test it out.

0
Well, it didn't work. I can add you to the TC, if you're still willing to help. DM me doom#5460 do_omsdayy 0 — 4y
Ad

Answer this question