Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't this making my character go to where the other brick is?

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)

3 answers

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

3 comments

0

This did not work. And now it's saying "Infinite yield possible on 'Jephi:WaitForChild("Torso")'"

0

The game is R6? Or R15?

0

R6

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.