How Can I Change The Position Of A Block (via Scripts)

So I know this is basic but I’ve never done this before so for me it’s not that basic anyway I want to make a while true do a script that makes a block change positions.

I made a script that changes it but it’s not really working.

If you cant fix the script then if you have an idea to make it work please help.

local one = game.workspace.MaponePos
local two = game.workspace.MaptwoPos
local block = game.workspace.Block

while true do
      block.Position =
      block.Position = game.workspace.two.Position

Are “MaponePos” and “MaptwoPos” Models or parts? If they are parts then it should work, but if they are models then you should specify which part of the model that the part should teleport to.

they are actually parts thats the problems its not working for some reason

You are indexing the part twice

First you indexed the part on line one:

local one = game.workspace.MaponePos

Then you did this:

block.Position =

which basically means:

block.Position =

Your code should look like this:

local one = workspace.MaponePos
local two = workspace.MaptwoPos
local block = workspace.Block

while true do
      block.Position = one.Position
      block.Position = two.Position
1 Like

Are you encountering any errors? If so, please post them here.(View->Output)

If you use CFrame that’s fine but if you index it like you did in your first post it will absolutely not work.

You are incorrect.

block.Position =

is interpreted as

block.Position = game['workspace']['one'].Position

Please do your research!


I was correcting Gecko on a statement he had made, not providing a solution. Please provide a screenshot of your hierarchy so we can further help you.

The two examples you gave mean the exact same thing. It’s just that the first example doesn’t work for names with spaces/special characters. Either way works just fine.

Also I tested my own code I realized workspace should be Workspace and works just fine. After that change the code works

You can just use workspace instead of game.Workspace.


Your post claimed that this code:

local one = game.Workspace.MaponePos
block.Position =

would be equivalent to

What I believe @thetacah meant was that is wrong because it is trying to reference an instance named ‘one’ that may not exist, not because it is referencing the Workspace twice.

1 Like

I just edited my first post with working code.

Woops, I realized I replied to the wrong user. However, the code can be as simple as this :

local Play = true -- // Play The Loop.

local Part1 = workspace.MaponePos -- // Directory of the first part to move to.
local Part2 = workspace.MaptwoPos -- // Directory of the second part to move to.

local MainBlock = workspace.Block -- // Directory of the main part to move.

local Delay = 5 -- // How long to wait in-between changing the position of the MainBlock.

while Play do -- // Loop.
     wait(Delay) -- // Wait.
     MainBlock.Position = Part1.Position -- // Go To Part1's Position.
     wait(Delay) -- // Wait.
     MainBlock.Position = Part2.Position -- // Go To Part2's Position.
end -- // End the loop.

This was mostly said by @lcgecko moments ago, but I tried making it a bit easier to understand / read. Was this all of your concern?

1 Like

I’m not sure that I understand what you mean?

Local x = a.b.c

Is the same as:

Local x = a[“b”].c

Guys if a block changes position via scripts and afterwards when someone teleports to it will it change where it will teleport?

Indeed, they are the same. The thing is, if b is missing, then :FindFirstChild should be used. So, something like this :

if a:FindFirstChild(“b”) then
    local B = a["b"]
    if B:FindFirstChild(“c”) then
         local C = B["c"]

Although, this isn’t necessary.

1 Like

You are using a script not a local script right? And it’s not disabled?

Is there an error that is returned when you run this?

Hmm, alright. Mind showing me how the workspace is setup?..

well its messy but the parts are directly in workspace they are in no model they are anchored