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.
local results = workspace.win:GetTouchingParts()
print(results)
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:
for i, v in pairs(results:GetDescentants()) do
local Seat
v:FindFirstChildWhichIsA("VehicleSeat")
if Seat then
end
end
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:
if Seat.Occupant ~= "" then
local player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
if player then
script.Parent.Winner.Text = "Winner is: " .. player.Name
end
end
Outstanding job! Now, I'll combine the scripts for you.
local results = workspace.win:GetTouchingParts()
print(results)
for i, v in pairs(results:GetDescentants()) do
local Seat
v:FindFirstChildWhichIsA("VehicleSeat")
if Seat then
if Seat.Occupant ~= "" then
local player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
if player then
script.Parent.Winner.Text = "Winner is: " .. player.Name
end
end
end
end
Please Accept if it works.
2 comments
you never told us the problem
@iiMegabyteGaming Thank you Did not notice.