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

How to teleport players to their cars?

Asked by 4 years ago

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) :

01local car1 = workspace.minigames.carrace.cars["Formula F1"].DriveSeat
02local car2 = workspace.minigames.carrace.cars["Formula F2"].DriveSeat
03local car3 = workspace.minigames.carrace.cars["Formula F3"].DriveSeat
04local car4 = workspace.minigames.carrace.cars["Formula F4"].DriveSeat
05local car5 = workspace.minigames.carrace.cars["Formula F5"].DriveSeat
06local car6 = workspace.minigames.carrace.cars["Formula F6"].DriveSeat
07local car7 = workspace.minigames.carrace.cars["Formula F7"].DriveSeat
08local car8 = workspace.minigames.carrace.cars["Formula F8"].DriveSeat
09 
10local playerModel = game.Players.LocalPlayer.Character
11local humanoid = playerModel:WaitForChild("Humanoid")
12        if car1.Occupant == nil and not humanoid.Seated then
13            print("car1")
14            car1.Value = true
15            game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = car1.Parent.CFrame
View all 52 lines...

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 :)

0
The problem is that it's in a local script. Ieowyyn 69 — 4y

1 answer

Log in to vote
1
Answered by
Ieowyyn 69
4 years ago

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.

01local car1 = workspace.minigames.carrace.cars["Formula F1"].DriveSeat
02local car2 = workspace.minigames.carrace.cars["Formula F2"].DriveSeat
03local car3 = workspace.minigames.carrace.cars["Formula F3"].DriveSeat
04local car4 = workspace.minigames.carrace.cars["Formula F4"].DriveSeat
05local car5 = workspace.minigames.carrace.cars["Formula F5"].DriveSeat
06local car6 = workspace.minigames.carrace.cars["Formula F6"].DriveSeat
07local car7 = workspace.minigames.carrace.cars["Formula F7"].DriveSeat
08local car8 = workspace.minigames.carrace.cars["Formula F8"].DriveSeat
09 
10local cars = {car1,car2,car3,car4,car5,car6,car7,car8}
11 
12game.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
View all 22 lines...

Have a great day or night!

0
It worked, Thank you! :) IzaXD123456 21 — 4y
Ad

Answer this question