Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this grid placement system 1x1?

This is a script that allows you to place block where ever you want them to be at be i want the gridstuds to be 4x4 not 1x1 but i don't know why it is 1x1 tried to change it but can't figure it out.

Heres the script + it is a localscript located in the startergui:

game:GetService("RunService").RenderStepped:connect(function()
	if Selected then
				
		local PlaceCFrame, X,Y,Z = nil, (Selected.Hitbox.Size.Z/2)%1, Selected.Hitbox.Size.Y/2, (Selected.Hitbox.Size.X/2)%1
		local p = ((CFrame.new(Mouse.hit.p, Camera.CFrame.p)*CFrame.new(0,0,-0.1))).p
		
		if Rotation0 == 0 then X,Z = (Selected.Hitbox.Size.X/2)%1, (Selected.Hitbox.Size.Z/2)%1 end
		
		Selected:SetPrimaryPartCFrame(CFrame.new(math.floor(p.X)+X,math.floor(p.Y+Y),math.floor(p.Z)+Z)*CFrame.Angles(0,math.rad(Rotation), math.rad(Toration)))
	end
end)

1 answer

✓ Accepted answer

I found your answer on a previous question.

local grid = 4
game:GetService("RunService").RenderStepped:connect(function()
    if Selected then

        local PlaceCFrame, X,Y,Z = nil, (Selected.Hitbox.Size.Z/2)%1, Selected.Hitbox.Size.Y/2, (Selected.Hitbox.Size.X/2)%1
        local p = CFrame.new(Vector3.new( (Mouse.Hit.x+(grid/2)) - (Mouse.Hit.x+(grid/2))%grid, Mouse.Hit.y, (Mouse.Hit.z+(grid/2)) - (Mouse.Hit.z+(grid/2))%grid, Camera.CFrame.p))*CFrame.new(0,0,-0.1).p

        if Rotation0 == 0 then X,Z = (Selected.Hitbox.Size.X/2)%1, (Selected.Hitbox.Size.Z/2)%1 end

        Selected:SetPrimaryPartCFrame(CFrame.new(math.floor(p.X)+X,math.floor(p.Y+Y),math.floor(p.Z)+Z)*CFrame.Angles(0,math.rad(Rotation), math.rad(Toration)))
    end
end)

2 comments

0

If i want "Y" to be the same grid how would i do that?

0

follow the pattern used in my answer

This discussion is preserved as it was. New answers, comments, and votes are closed.