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

How would I automatically align blocks to a grid through a script?

Asked by 10 years ago

Since I was not clear enough about the previous post, I have reposted this question. I have attempted at making a script like this various times, but not once successful. How would I do this? I am not asking for a script, but a function that would aid me in making a script as such.

0
Are you talking about positioning it? Shawnyg 4330 — 10y
0
Yes, onto a grid. xolbStudios 127 — 10y
0
Mind giving an example? Shawnyg 4330 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

Oh, glorious for loops.

for x=1, 10 do  -- Edit this to your needs
    for y=1, 10 do  -- This too
        local p = Instance.new("Part", workspace)
        p.Anchored = true
        p.FormFactor = "Custom"
        p.Size = Vector3.new(.5, .5, .5)
        p.Position = Vector3.new(x, y, 0)  -- Possibly this also
        wait()
    end
end

You can extend the grid to 3d space like so:

for x=1, 10 do
    for y=1, 10 do
        for z=1, 10 do
            local p = Instance.new("Part", workspace)
            p.Anchored = true
            p.FormFactor = "Custom"
            p.Size = Vector3.new(.5, .5, .5)
            p.Position = Vector3.new(x, y, z)
        end
    end
end

PLEASE NOTE that the wait() will majorly slow down loading times on large-scale operations. It is perfectly safe to remove the wait(), however users will experience either a freeze, or some minor lag.

0
I was thinking up and down as well. I don't think this would work with new parts that people are placing. This answer is good, but it is semi-irrelevant to my question. xolbStudios 127 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

I encountered this problem a few days ago, and it was by (almost) complete accident that I discovered the solution. I was actually researching something else when I saw the math.floor() (function? method? whatever you want to call it) I stuck this code inside a mouse.Moved function to great results.

        position = mouse.Hit.p
        posX = math.floor(position.X)
        posY = position.Y
        posZ = math.floor(position.Z)
        endX = math.floor((posX/10)) * 10
        endZ = math.floor((posZ/10)) * 10

Combined with a script to place blocks (I'm assuming you don't want to use mine) this will align placed blocks in a 10x10 grid arrangement. You can probably nest the math.floor()s, but I didn't bother for reasons that only make sense to me :3

Anyway I hope this helps, and if you (for some reason) do want my block placing script I would be happy to give it to you. (Although my script does need to be changed to a raycasting method)

Answer this question