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

How do I make a car delete if a person sitting in the driver's seat leaves the game?

Asked by 4 years ago
Edited 4 years ago

I still cannot figure this one out. I am trying to delete a car if a person sitting in the driver's seat leaves the game.

local Seat = script.Parent

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

Any help is appreciated. (the script is in the seat)

1 answer

Log in to vote
0
Answered by 4 years ago
local Players = game:GetService("Players") -- Player Service

Players.PlayerRemoving:Connect(function(User) -- User Arguement
  local Humanoid = User.Character:FindFirstChildOfClass("Humanoid") -- Humanoid.
  Humanoid.SeatPart:Destroy() -- The seat the user sitting in.
end)

The seat part will be the seat part not the model, you can figure this from here on now. Hope this helped, make sure to give a response if you need anything else.

Ad

Answer this question