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

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.

2 Likes

Your post claimed that this code:

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

would be equivalent to game.Workspace.game.Workspace.MaponePos.Position

What I believe @thetacah meant was that game.Workspace.one.Position 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?
This:

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"]
         
    end
end

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

Hmm, mind showing me how you set it up though?.. Preferably a screen shot.

If your code looks like the code in my first post it should work.

I tested it with three parts in the workspace. Make sure you aren’t trying to move models.

I agree that it is the same, but that wasn’t the issue I was referring to. In your first post on this thread it looks like you were saying that something like:

local x = workspace.a.b.c
local y = workspace.x

is the same as:

local y = workspace.workspace.a.b.c

But obviously it isn’t. In the statement y = workspace.x, the ‘x’ is not substituted with ‘a.b.c’. It is just treated like y = workspace["x"] which means it would be referencing something named ‘x’, not the object referenced by ‘a.b.c’

That was most likely a typo that they forgot to check back on.

its long but sure why not give me one sec

PICTURE:
DirectllyIne

Is this a local script or a server script? If you are running a game instead of playtesting, local scripts don’t run. If those things don’t work, use Vector3 instead:

local block = game.workspace.Block

while true do
    wait(5)
    block.Position = Vector3.new() -- One position here
    wait(5)
    block.Position = Vector3.new() -- Two position here
end

But the true error of your code is on how you indexed the code:

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

while true do
    wait(5)
    block.Position = game.workspace.one.Position -- This means game.workspace.game.workspace.MaponePos.Position
    wait(5)
    block.Position = game.workspace.two.Position
end

To fix that do this:

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

while true do
    wait(5)
    block.Position = one.Position
    wait(5)
    block.Position = two.Position
end

I am using this code that someone said it works with it but its not working
local Play = true – // Play The Loop.

local Part1 = workspace.GameOne – // Directory of the first part to move to.
local Part2 = workspace.GameTwo – // Directory of the second part to move to.

local MainBlock = workspace.Game – // 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.

What type of script is this?.. A local or a normal?..