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

How do I teleport a player to a brick, without getting an error?

Asked by 8 years ago
Edited 8 years ago

I have a TextButton that when the player clicks, will teleport them to their car. In another script the car gets spawned into the game in the players folder located in Workspace. The "TeleportPlayer" is a brick in the body model of the car.

script.Parent.MouseButton1Click:connect(function()

    local playerfol = game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name .."Car")
    local player = game.Players.LocalPlayer
    player.Character.Torso.CFrame = game.Workspace:FindFirstChild(playerfol.DefaultCar.Body.TeleportPlayer.CFrame)

end)

So I followed what the wiki said to set it up, and I believe it is correct, but I'm getting this error.

bad argument #3 to 'CFrame' (CFrame expected, got nil)

*I also added a slight wait between the car spawn and player teleport to give time for the model to spawn in correctly.

Any ideas on how to fix this?

0
Look at the error part of the wiki. SH_Helper 61 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

You indexed the CFrame property of the child, so the script will try to find a CFrame object, which you don't have, which is why it is nil.

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

If i'm correct this would work, if it does please accept the answer.

local playerfol = game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name .."Car")
local player = game.Players.LocalPlayer 
local TpTarget = playerfol.DefaultCar.Body:WaitForChild(TeleportPlayer) -- Searching for TeleportPlayer in Body

script.Parent.MouseButton1Click:connect(function()
    player.Character.Torso.CFrame = CFrame.new(TeleportPlayer.Position)

end)
0
Hey. I used your code and I'm getting this error. " Infinite yield possible on 'Workspace:WaitForChild("Instance")" ViciousViperV2 24 — 8y
0
Oh, i'm stupid.. fixing it DjinoKip 78 — 8y
0
Fixed it. DjinoKip 78 — 8y

Answer this question