Placement system

hello everyone, i am making a tycoon with placement system but i have a problem with the grid.

currently i am using:
newCframe = CFrame.new(math.floor(mouse.Hit.X / TILE +.5) * TILE, math.floor(mouse.Hit.Y / 5 +.5) * 5, math.floor(mouse.Hit.Z / TILE +.5) * TILE) * CFrame.Angles(0,math.rad(ROT),0)

and then i tween the models primarypart to “newCFrame”

its works fine if the model that needs to be placed is the size of TILE wich is 3.5 studs.
but i want to be able to place walls with a difrent grid of 7 but it stil needs to be aligned to the grid of TILE,
since ive never been good at math i cant find a solution for this.

this is what currently happens:

What i want to happen:

thnx for helping me out! :smiley:

1 Like

This belongs in #help-and-feedback:scripting-support.

Why does it need to be aligned to the grid of TILE? I would simply change the value of TILE to 7.

1 Like

if i change the grid to 7 this happens:

but i want it to align i could solve this problem by making the walls 1 tile but then they are to small

Hmm… how about lowering the grid size then, say, 3?

nope if i do that the problem stays the same. :frowning:

There’s a tutorial on the DevForum on how to make a placement system, maybe you could use that. Here’s the link: How to use Placement Service

Also, there’s a YouTube series on how to make a Sandbox Tycoon game: https://www.youtube.com/watch?v=KJpSI_L8500&list=PLR9RLF7-52bSg0BcGfV2zyvFyFMJwztTt

And, if you want to keep your placement system, i couldn’t help you with that because i don’t know a thing about Lua. Have a good day!

Hmm… looks like a snapping issue… I suggest you take a look at this article in ScriptingHelpers, particularly the section on snapping.

And if you’re looking to make a more advanced system which also saves items you place, this article is a good choice

Note that this article is more advanced and requires a moderate knowledge of Lua and OOP, so if you’re new to scripting I’d suggest you try the first to make a script from the first article and then gradually learn new features and move to the second one.

thnx for trying but this is not the problem i have

im using math.floor(mouse.Hit.Position / grid) * grid

but if i change the grid from 3.5 to 7 its not aligned with eachother to solve this i would have to change where the grid position starts 0,0,0 but idk how and in what way

okay so i found what to do. i dit this to calculate the grid position:
newCframe = CFrame.new(math.floor(mouse.Hit.X / TILE +.5) * TILE + TILE/factor, math.floor(mouse.Hit.Y / 5 +.5) * 5, math.floor(mouse.Hit.Z / TILE +.5) * TILE + TILE/factor) * CFrame.Angles(0,math.rad(ROT),0)

but as soon as i wanted to place a model with a bigger primarypart that model went of grid.my solution was this:

if dummys[currentObject.Value].PrimaryPart.Size.X > 3.5 then
                local factor = model.PrimaryPart.Size.X / TILE
                newCframe = CFrame.new(math.floor(mouse.Hit.X / TILE +.5) * TILE + TILE/factor, math.floor(mouse.Hit.Y / 5 +.5) * 5, math.floor(mouse.Hit.Z / TILE +.5) * TILE + TILE/factor) * CFrame.Angles(0,math.rad(ROT),0)
            else
                newCframe = CFrame.new(math.floor(mouse.Hit.X / TILE +.5) * TILE, math.floor(mouse.Hit.Y / 5 +.5) * 5, math.floor(mouse.Hit.Z / TILE +.5) * TILE) * CFrame.Angles(0,math.rad(ROT),0)
            end