It works fine in studio, but not in-game. The script is a LocalScript.
In the console output it says "Torso is not a valid member of Model" on line 8
local b = script.Parent local ply = game.Players.LocalPlayer.Character local tpos = game.Workspace:WaitForChild(tostring(script.Parent.Name)):WaitForChild("TeleportBrick").CFrame repeat wait() until tpos repeat wait() until ply b.MouseButton1Down:connect(function() ply.Torso.CFrame = tpos end)
I did some experimenting in ROBLOX Studio and the code below seems to work.
You can add a wait() at the beginning to be safe when calling variables.
Also, adding the two repeat wait() until loops is kind of redundant, since WaitForChild already does that.
In addition, the "Infinite yield possible" is nothing to worry about since it's just ROBLOX's way of warning that WaitForChild (the wait() loop) could go on forever until the child is found.
TIP: A nice way to distinguish an error and a warning is the color of the text. Red is an error and yellow is a warning.
wait() local b = script.Parent local ply = game.Players.LocalPlayer.Character local tpos = game.Workspace:WaitForChild("TeleportBrick").CFrame b.MouseButton1Down:connect(function() ply:WaitForChild("Torso").CFrame = tpos end)
Hope this works. Good luck!
Typically, objects don't load fast enough thus casting an error, in the following case, use the method WaitForChild
.
ply:WaitForChild("Torso").CFrame = tpos
Use the Move event, It will move the player without breaking anything, risk free. Only down side is things like arm rotation will reset. The example below is very basic.
Example:
local Plr = game.Players.Player1 Plr:Move(Vector3.new(0, 0, 0), true)