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

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

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)

2 comments

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

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

1 answer

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.

1 comment

0

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

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