Building Tool Problem

Hello again! You probably have seen me before. If not, welcome! Now today’s problem is about this thing. You move your cursor and a random brick pops up. It’s like build a boat’s building system but only cursor movement. There are a couple of problems I need to discuss.

The problem was when I was in - game moving my cursor the brick showed up (Good news) but bad news is it kept like going off screen and going into the ground. Here’s evidence:

See what I mean now?

script:

local player = game.Players.LocalPlayer
local workspacepart = game:GetService("Workspace")
local partsgo = Instance.new("Model",workspacepart)
	partsgo.Name = "ModelParts"
local madepart = Instance.new("Part",partsgo)
	madepart.Size = Vector3.new(3,3,3)
	madepart.Name = (player.Name.." Part")
	madepart.Anchored = true
local mouse = player:GetMouse()

while true do
	wait()
	madepart.CFrame = CFrame.new(mouse.Hit.x/1,mouse.Hit.y/1,mouse.Hit.z)
end

Why are you dividing the x and y values by 1? You’d just get the same value…

Also, it is ill-advised to use Instance.new() with the parent argument, as seen below!

Thanks for the response; I will check this method…

I don’t think it really worked.

local player = game.Players.LocalPlayer
local workspacepart = game:GetService("Workspace")
local partsgo = Instance.new("Model")
	partsgo.Name = "ModelParts"
	partsgo.Parent = workspacepart
local madepart = Instance.new("Part")
	madepart.Parent = partsgo
	madepart.Size = Vector3.new(3,3,3)
	madepart.Name = (player.Name.." Part")
	madepart.Anchored = true
local mouse = player:GetMouse()

while true do
	wait()
	madepart.CFrame = CFrame.new(mouse.Hit.x,mouse.Hit.y,mouse.Hit.z)
end

this is happening because mouse.Hit is moved onto the surface of the part and then the part gets moved onto the new mouse.Hit and this keeps on stacking which is why it goes of the screen. an easy fix to this is setting the TargetFilter property of the mouse to the part your moving so that mouse.Hit ignores it.

mouse.TargetFilter = madepart

if you want it to stop going in the ground you could add half of its y size to its cframe which just pops it up by half of its size.

madepart.CFrame = CFrame.new(mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z) + Vector3.new(0, madepart.Size.Y / 2, 0)
1 Like
(math.ceil(mouse.Hit.p.X), .5, math.ceil(mouse.Hit.p.Z))

I use math.ceil to get a rounded number and for the y I set it to .5 or 1 so its always the same.

also mouse.Hit.p and not mouse.Hit

1 Like

The issues that are shown here are 2 things. Brick is in the ground can be fixed by Vector3 movement to the brick by half of its y size. This is the same for anything you build. Position is the very center of the object. The second issue I saw was the part going all the way to the camera. This could be fixed by destroying a part and making a new one before you get the Mouse.Hit location.

1 Like

Thanks for the response. It did work! :smiley:

1 Like

roas your response is good. I have a new problem.