Hi! I wanted to make a race game but I don't know how to teleport players to their cars. Here's my local script located in starter player scripts(SPS) :
01 | local car 1 = workspace.minigames.carrace.cars [ "Formula F1" ] .DriveSeat |
02 | local car 2 = workspace.minigames.carrace.cars [ "Formula F2" ] .DriveSeat |
03 | local car 3 = workspace.minigames.carrace.cars [ "Formula F3" ] .DriveSeat |
04 | local car 4 = workspace.minigames.carrace.cars [ "Formula F4" ] .DriveSeat |
05 | local car 5 = workspace.minigames.carrace.cars [ "Formula F5" ] .DriveSeat |
06 | local car 6 = workspace.minigames.carrace.cars [ "Formula F6" ] .DriveSeat |
07 | local car 7 = workspace.minigames.carrace.cars [ "Formula F7" ] .DriveSeat |
08 | local car 8 = workspace.minigames.carrace.cars [ "Formula F8" ] .DriveSeat |
09 |
10 | local playerModel = game.Players.LocalPlayer.Character |
11 | local humanoid = playerModel:WaitForChild( "Humanoid" ) |
12 | if car 1. Occupant = = nil and not humanoid.Seated then |
13 | print ( "car1" ) |
14 | car 1. Value = true |
15 | game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = car 1. Parent.CFrame |
the problem is that nothing works at all. (nothing prints or teleports) I thought the best way would be to check that the player is sitting and that the seat it is sitting on is occupied. Thanks for every answer :)
The problem is that it's in a local script. If you want to get a player in a server script, use PlayerAdded and CharacterAdded. Also, there's a much easier way instead of constantly clone and edit the numbers of each statement.
01 | local car 1 = workspace.minigames.carrace.cars [ "Formula F1" ] .DriveSeat |
02 | local car 2 = workspace.minigames.carrace.cars [ "Formula F2" ] .DriveSeat |
03 | local car 3 = workspace.minigames.carrace.cars [ "Formula F3" ] .DriveSeat |
04 | local car 4 = workspace.minigames.carrace.cars [ "Formula F4" ] .DriveSeat |
05 | local car 5 = workspace.minigames.carrace.cars [ "Formula F5" ] .DriveSeat |
06 | local car 6 = workspace.minigames.carrace.cars [ "Formula F6" ] .DriveSeat |
07 | local car 7 = workspace.minigames.carrace.cars [ "Formula F7" ] .DriveSeat |
08 | local car 8 = workspace.minigames.carrace.cars [ "Formula F8" ] .DriveSeat |
09 |
10 | local cars = { car 1 ,car 2 ,car 3 ,car 4 ,car 5 ,car 6 ,car 7 ,car 8 } |
11 |
12 | game.Players.PlayerAdded:Connect( function (player) -- once a player joins, the script starts and creates the "player" variable |
13 | player.CharacterAdded:Connect( function (character) -- then when the character is added, it creates another variable |
14 | for _,car in pairs (cars) do -- start the loop |
15 | if car.Occupant = = nil and not character.Humanoid.Seated then |
Have a great day or night!