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

How to put a block to the sides of other blocks?

Hello!

I want to make a build tool to build anything. Basically, my tool works well... However, the blocks that I want to put doesn't appear on the sides of other blocks. Exactly, when I hover the mouse, for example, on the side of a pillar, then when I press the left mouse button, the block appears on pillar's top, and not where my mouse is or not on the side of the pillar.

Here's my localscript inside my tool:

--- Services ---
local rs = game:GetService("ReplicatedStorage")

--- Modules ---
local BlockModule = require(rs.BlockModule)
local ImageModule = require(rs.ImageModule)
local WeldModule = require(rs.WeldModule)

--- Variables ---
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

local tool = script.Parent

local function round(number,increment)
	number = math.floor(number)
	number = number-(number%increment)
	return number
end

--- Actual Code ---
tool.Equipped:Connect(function()
	local placement = rs.Blocks:FindFirstChild("Part"):Clone()
	placement.Anchored = true
	placement.Transparency = 0.5
	placement.CanTouch = false
	mouse.TargetFilter = placement
	
	placementmodel = Instance.new("Model",workspace)
	placementmodel.Name = player.Name.."'s placement"
	placement.Parent = placementmodel
	placementmodel.PrimaryPart = placement
	
	movePlacement = game:GetService("RunService").Stepped:Connect(function() -- it makes placement of selected block follow player's mouse
		placementmodel:MoveTo(Vector3.new(round(mouse.Hit.Position.X,1),round(mouse.Hit.Position.Y,1),round(mouse.Hit.Position.Z,1)))
	end)
	
	onMouseClick = mouse.Button1Down:Connect(function()
		rs.Place:FireServer("Part", placementmodel.PrimaryPart.Position)
	end)
end)
tool.Unequipped:Connect(function()
	onMouseClick:Disconnect()
	movePlacement:Disconnect()
	placementmodel:Destroy()
end)

I hope I explained my problem clearly.

1 answer

✓ Accepted answer

when you do

movePlacement = game:GetService("RunService").Stepped:Connect(function() -- it makes placement of selected block follow player's mouse
placementmodel:MoveTo(Vector3.new(round(mouse.Hit.Position.X,1),round(mouse.Hit.Position.Y,1),round(mouse.Hit.Position.Z,1)))
end)

instead of

placementmodel:MoveTo(Vector3.new(round(mouse.Hit.Position.X,1),round(mouse.Hit.Position.Y,1),round(mouse.Hit.Position.Z,1)))

do

placementmodel:PivotTo(CFrame.new(Vector3.new(round(mouse.Hit.Position.X,1),round(mouse.Hit.Position.Y,1),round(mouse.Hit.Position.Z,1))))

this is because :MoveTo() uses physics slightly more, as the part you create (likely) has collisions on, it moves on top because it cant fit into the given placement, whereas :PivotTo() ignores physical properties and just moves it instantly, sorry if this isnt that clear though!

lmk if this works!

1 comment

0

Thanks for the help, now the block can really be located on the sides of other blocks! But now I have the following problem: when the mouse hovers over some block, placement falls into it by half but CanCollide property of placement is true. I think it happened because of my understatement in this topic. Is there any solution to problem that causes placement to penetrate into other blocks by half?

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