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

How To Place Parts in BlockFormat like Minicraft?

Asked by 4 years ago
Edited 4 years ago

Thank You For your time and afford hi, I have a problem I made a script that when a player clicks a Part is Created where the mouse position clicked but I want to have a structure like Minecraft when I create a part next to apart it's not crooked it's exactly next to it here is the script for creating the part and

local part=Instance.new("Part")     

part.Parent=script.Parent:WaitForChild("Craft")

local clickdetector=Instance.new("ClickDetector")
local scriptfordestroy=rightclickscript:Clone()
clickdetector.Parent=part
scriptfordestroy.Parent=clickdetector
part.Anchored=false
part.CFrame=CFrame.new(mouseposx,mouseposy+1,mouseposz)
part.Rotation = Vector3.new(0,0,0)
part.Size=Vector3.new(2.2,2.2,2.2)
part.BrickColor=BrickColor.new(brickcolor)

here is what i mean when i want to create it https://pasteboard.co/J6bknzS.png

1 answer

Log in to vote
0
Answered by
ScuffedAI 435 Moderation Voter
4 years ago

If you want to the cubes to stick to each other like a grid, then you want to take each axis and convert to a new value before applying to the part. math.floor(axis / cubeSize) * cubeSize

local part=Instance.new("Part")
local cubeSize = 2.2 

function convert(axis)
    return math.floor(axis / cubeSize) * cubeSize
end

local clickdetector=Instance.new("ClickDetector",part)
local scriptfordestroy=rightclickscript:Clone()

local x,y,z = convert(mouseposx),
    convert(mouseposy),
    convert(mouseposz)

scriptfordestroy.Parent=clickdetector
part.Anchored=false
part.CFrame=CFrame.new(x,y,z)
part.Rotation = Vector3.new(0,0,0)
part.Size=Vector3.new(cubeSize,cubeSize,cubeSize)
part.BrickColor=BrickColor.new(brickcolor)

part.Parent = script.Parent:WaitForChild("Craft")
0
thanks ScuffedAI thank you it worked but these parts glitch on eatch others because i have anchored on do you know any solution that these parts don't collide with anochered on my solution was to first turn anochered off so that it pushed the other part and then wait a 0.1 second and then turn anochered on but that was not the best solution do u know something SchuffedAI. you_success -50 — 4y
Ad

Answer this question