I am just starting to learn how to use position and I am confused. I believe the answer is in the lines of:
local hit = Workspace.WiseDumbledore Workspace.Part.Position = (hit.x,hit.y,hit.z)
Is that correct? Please correct me if I am wrong.
It's close to being correct, but in roblox, you use vectors for positions and forces.
local hit = game.Workspace.WiseDumbledore.Torso.Position game.Workspace.Part.Position = hit --Since 'hit' is already an vector, you don't need to use 'Vector.new()'
If you want the part to get moved to that exact position, ignoring the fact that there are other parts in the way, you use coordinate frame variable(CFrame):
local hit = game.Workspace.WiseDumbledore.Torso.Position game.Workspace.Part.CFrame= CFrame.new(hit)
I think it would display an Error. You haven't specified the player, instead, your
hit variable is in Workspace, Players are not in Workspace. Line 2 looks correct.
Now it depends really, if you want this to be repeated, you need to add a loop. There are many loops. The
while true do loop makes it go forever. I am not so familiar with other loops, since I need to revise them. If you wish to do the
while true do loop, the following code should be correct:
hit = AAA -- First of all, Find the player's TORSO... Replace "AAA" With the Torso's Path (eg: game.Players. etc... Part = Workspace.Part --The Part that you want to teleport while true do --Keeps this going on forever Part.Position = Vector3.new(hit.Position.x, hit.Position.y, hit.Position.z) --You forgot the Vector3.new(). wait() --Add how many second it should wait before moving again. Or leave it, so that it doesn't crash. end --[[ NOTE: Always leave a "wait() " in the loop, or else Studio WILL Crash.]]
No, it is not correct.
Position is a property of
BasePart, but WiseDumbledore is a
Model, a Model does not have
z as Properties.
What you should do is get the position (a
Vector3) of the Torso (a specific part of the Character) and then you can assign it to the Part that you want:
positionOfTorso = workspace.WiseDumbledore.Torso.Position workspace.Part.Position = positionOfTorso
Alternatively, you can set the
CFrame (CoordinateFrame) of the Part and this will allow you to put parts inside each other (i.e. instead of placing the Part on top of the player)
positionOfTorso = workspace.WiseDumbledore.Torso.Position workspace.Part.CFrame = CFrame.new(positionOfTorso)
... or you could just do it in one line by referring directly to the
CFrame of the Torso
workspace.Part.CFrame = workspace.WiseDumbledore.Torso.CFrame
Hope that helps!