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

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

Asked by
Jephi 42
8 years ago

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

Log in to vote
1
Answered by 8 years ago

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!

Ad
Log in to vote
0
Answered by
rexbit 707 Moderation Voter
8 years ago

Typically, objects don't load fast enough thus casting an error, in the following case, use the method WaitForChild.

ply:WaitForChild("Torso").CFrame = tpos
0
This did not work. And now it's saying "Infinite yield possible on 'Jephi:WaitForChild("Torso")'" Jephi 42 — 8y
0
The game is R6? Or R15? rexbit 707 — 8y
0
R6 Jephi 42 — 8y
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
8 years ago

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)

Answer this question