#Moving a bunch of parts or instancing them in?

1 messages · Page 1 of 1 (latest)

sand night
#

In my game with multiple maps i'd like to know if its better to move the row of parts in the images or instance them in.

Im currently trying to figure out the move approach I am thinking of basically manually entrying the position of a part in a row into a table, if there is a better way to move the parts i'd much rather do that

thank you

#

id rather not do the painful task of copying and pasting and manually inputing the data

#

or acutally i could just store the start pos of the grid and then just move them to pos using an offset

bitter needle
#

You could use for loops to get the grid

signal birch
#

there is not enough information for me to answer this question

sand night
#

the problem is i have multiple maps and the game picks a random map which is located away from each other

#

the players are then tped to the selected map

#

my question is how do i move the parts or instead create new ones?

#

each row are 4x4 studs and theres 10 of them

#

and there are 10 rows

signal birch
#

you multple maps far away from each other

sand night
signal birch
#

then you teleport the players to a random map

sand night
#

yea

signal birch
#

then the players place blocks at that map

sand night
#

yeah they can place it on the rows*

signal birch
#

then once round ends you teleport them back

sand night
#

yup

signal birch
#

and you want to know if you should reuse the old blocks

#

or delete them and make new ones?

sand night
#

yes

signal birch
#

reuse them

sand night
#

ok

#

how would u store where they'd go

signal birch
#
local deletedBlocks = {}

local function CreateBlock(color)
    local block = table.remove(deletedBlocks)
    if block == nil then
        block = instance.new("Part")
        block.Anchored = true
    end
    block.Color = color
    return block
end

local function DeleteBlock(block)
    table.insert(deletedBlocks, block)
    block.Parent = nil
end

local red = Color3.new(1, 0, 0)
local block = CreateBlock(red)
task.wait(1)
DeleteBlock(block)
sand night
#

wait so i create new blocks?

signal birch
sand night
#

i was thinking i'd just move these blocks to the new map picked

#

and i store where they go somewhere

signal birch
sand night
#

oh so its better to instace them in?

sand night
signal birch
sand night
signal birch
#

well look at my code i just showed you

sand night
#

ok but if i was to reuse them

signal birch
#

first you delete all the old blocks using the DeleteBlock function

#

this will put all them blocks in the table

#

then you use the CreateBlock function

#

this will first try to get a block from the table

#

and reuse that

#

but if the table is empty then it will make a new one

sand night
#

ohhh

#

yeah okay but how do i move them to the maps now

signal birch
#
local deletedBlocks = {}
local red = Color3.new(1, 0, 0)

local function CreateBlock(position, color)
    local block = table.remove(deletedBlocks)
    if block == nil then
        block = instance.new("Part")
        block.Anchored = true
    end
    block.Position = position
    block.Color = color
    return block
end

local function DeleteBlock(block)
    table.insert(deletedBlocks, block)
    block.Parent = nil
end

local block = CreateBlock(Vector3.new(0, 0, 0), red)
task.wait(1)
DeleteBlock(block)
sand night
#

ok how do i store where they go

#

if i want to make a 10x10 grid of rows and columns do i store the start position

signal birch
#

anyway you like

sand night
#

like first row first coloumn

sand night
signal birch
#

you can just have a array of positions

sand night
signal birch
#
positions = {1, 42, 64, 75, 567, 5, 34, 6, 9}

-- first delete all old blocks
for index, block in blocks do
    DeleteBlock(block)
end

-- now make all new blocks
for index = 1, #positions, 3 do
    CreateBlock(Vector3.new(positions[index], positions[index + 1], positions[index + 2]), red)
end
#

this would be the most optimal way

#

but your free to do it anyway you like

sand night
#

okokokokok

#

ah thanks a bunch

signal birch
#

its just a list of x y z cords

#

of where all the blocks go

sand night
#

oh right i didnt pay attention

signal birch
#

one block will be at 1, 42, 64 another at 75, 567, 5 and another at 34, 6, 9

sand night
#

ah right right

signal birch
#

thats there X Y Z cords

#

you can multiply it by the block size

sand night
#

as in?

signal birch
#

(1, 42, 64) * blockSize

sand night
#

what would that do

signal birch
#

if blocks are 4x4x4 studs

#

then it will make the coordinates align correctly

sand night
#

on what axis

signal birch
#

or you could save the coordinates with the scale baked in

sand night
#

i think i only need the x or z

#

yeah i was thinking i'd just move them by 4 studs to the right per iteration or something

#

and once 10 iterations and over move them down

#

and do that 10 times

signal birch
sand night
#

i thought u could just move them to the right by 4 studs

#

ok thats good to know i'd have to spend a week figuring that out

signal birch
#

you could just put the maps in serverstorage

#

then when the server starts loop over each block

#

and save there position in a table

#

then destroy the map once the positons are inside the table

#
local map1 = {}
for index, block in serverStorage.Map1:GetChildren() do
  table.insert(map1, block.Position)
  DeleteBlock(block)
end
serverstorage.Map1:Destroy()
#

just do this

#
for index, position in map1 do
    CreateBlock(position, red), 
end

to load the map again

sand night
#

saves lines of code too yeah ima do that