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?
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.
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)