Answered by
4 years ago Edited 4 years ago
To make it detect it if a car hit the winner's part, we'll have to use the
GetTouchingParts method. Please note that this does not count objects that have their CanCollide property set to false.
Anyways, let's begin. First, we'll have to detect the touching parts, to do this, let's use GetTouchingParts.
1 | local results = workspace.win:GetTouchingParts() |
Once we do that, we'll have to detect if there is a Vehicle Seat inside of one of the Touching Parts. To do this, we can use i, v in pairs and GetDescendants and use FindFirstChildWhichIsA to find if it exist.
Code:
1 | for i, v in pairs (results:GetDescentants()) do |
3 | v:FindFirstChildWhichIsA( "VehicleSeat" ) |
Once we do that, we'll have to detect who is inside of the seat. To do this, we can use: Seat.Occupant.Parent, which is the character and GetPlayerFromCharacter. (Also, we'll need to detect if they are a player and the change the Winner Text.
Code:
1 | if Seat.Occupant ~ = "" then |
2 | local player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent) |
4 | script.Parent.Winner.Text = "Winner is: " .. player.Name |
Outstanding job! Now, I'll combine the scripts for you.
01 | local results = workspace.win:GetTouchingParts() |
03 | for i, v in pairs (results:GetDescentants()) do |
05 | v:FindFirstChildWhichIsA( "VehicleSeat" ) |
07 | if Seat.Occupant ~ = "" then |
08 | local player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent) |
10 | script.Parent.Winner.Text = "Winner is: " .. player.Name |
Please Accept if it works.