Placement system offgrid

Hello, so I have been working on a placement system and I have got alot of it done but for some reason why i try to place a block its of grid and the cencter of it is a bit away from the mouse when the mouse should always be in the center of the block.
I coudnt get my mouse in the picture sorry
NotToGrid
as you can see in the picture its not in the grid it in the middle of 4.

script

--Blocks
local Block = script.Parent:WaitForChild("Block")
local Wedge = script.Parent:WaitForChild("Wedge")
local Cwedge = script.Parent:WaitForChild("CornorWedge")

--ReplicatedStorage
local Items = game.ReplicatedStorage:WaitForChild("PlacementFolder")
local Event = game.ReplicatedStorage:WaitForChild("PlacementEvent")
local DeleteEvent = game.ReplicatedStorage:WaitForChild("DeletementEvent")

--Parts
local ChosenBlock = Items:GetChildren()[1]
local sound = script:WaitForChild("Place")
local mouse = game.Players.LocalPlayer:GetMouse()
local CancelBuild = script.Parent:WaitForChild("CancelBuild")
local RunService = game:GetService("RunService")
local GoodToPlace = true
local maxPlacingDistance = 50
local PlacingObject = false
local CanDelete = false
local PreviewObjectMain = nil

--Block Funtions
Block.MouseButton1Click:Connect(function()
	if PlacingObject == false then
		PlacingObject = true
		ChosenBlock = Items.Block.Name
		CancelBuild.Visible = true
		
		local PreviewObject = Items:WaitForChild("Block"):Clone()
		PreviewObject.Parent = game.Workspace
		PreviewObjectMain = PreviewObject
		
		for i, Parts in pairs(PreviewObject:GetDescendants()) do
			if Parts:IsA("BasePart") then
				
				Parts.Transparency = 0.5
				Parts.CanCollide = false
			end
		end
		CancelBuild.MouseButton1Click:Connect(function()
			PlacingObject = false
			CancelBuild.Visible = false
			PreviewObject:Destroy()
		end)
		mouse.Button1Up:Connect(function()
			wait(0.1)
			CancelBuild.Visible = false
			PreviewObject:Destroy()
		end)
	end
end)

Wedge.MouseButton1Click:Connect(function()
	if PlacingObject == false then
		PlacingObject = true
		ChosenBlock = Items.Wedge.Name
		CancelBuild.Visible = true

		local PreviewObject = Items:WaitForChild("Wedge"):Clone()
		PreviewObject.Parent = game.Workspace
		PreviewObjectMain = PreviewObject

		for i, Parts in pairs(PreviewObject:GetDescendants()) do
			if Parts:IsA("BasePart") then

				Parts.Transparency = 0.5
				Parts.CanCollide = false
			end
		end
		CancelBuild.MouseButton1Click:Connect(function()
			PlacingObject = false
			CancelBuild.Visible = false
			PreviewObject:Destroy()
		end)
		mouse.Button1Up:Connect(function()
			wait(0.1)
			CancelBuild.Visible = false
			PreviewObject:Destroy()
		end)
	end
end)

Cwedge.MouseButton1Click:Connect(function()
	if PlacingObject == false then
		PlacingObject = true
		ChosenBlock = Items.Cwedge.Name
		CancelBuild.Visible = true

		local PreviewObject = Items:WaitForChild("Cwedge"):Clone()
		PreviewObject.Parent = game.Workspace
		PreviewObjectMain = PreviewObject

		for i, Parts in pairs(PreviewObject:GetDescendants()) do
			if Parts:IsA("BasePart") then

				Parts.Transparency = 0.5
				Parts.CanCollide = false
			end
		end
		CancelBuild.MouseButton1Click:Connect(function()
			PlacingObject = false
			CancelBuild.Visible = false
			PreviewObject:Destroy()
		end)
		mouse.Button1Up:Connect(function()
			wait(0.1)
			CancelBuild.Visible = false
			PreviewObject:Destroy()
		end)
	end
end)

RunService.RenderStepped:Connect(function(targetSurface)
	if PlacingObject == true then
		mouse.TargetFilter = PreviewObjectMain
		if PreviewObjectMain:FindFirstChild("MainPart") then
			local target = mouse.Target
			
			local y = math.floor(mouse.Hit.Position.Y / 2) * 2 + 1.75
			local x = math.floor(mouse.Hit.Position.X / 2) * 2
			local z = math.floor(mouse.Hit.Position.Z / 2) * 2

			local ObjectCFrame = CFrame.new(x, y, z)
			PreviewObjectMain:SetPrimaryPartCFrame(ObjectCFrame)
		end
	end
end)

mouse.Button1Up:Connect(function()
	if PlacingObject == true then
		PlacingObject = false
		sound:Play()
		Event:FireServer(PreviewObjectMain.Name, PreviewObjectMain.PrimaryPart.CFrame)
	end
end)

thanks for any help.

1 Like

You need to offset the grid texture, the grid texture is offset by 2 studs for some reason.

Its hard to explane this but with the preview block the mouse is meant to always be in the middle of it but for some reason its always on the outside of it.

Do you know how I can fix this?

Can you send me a video showing the problem please? Because I really don’t understand. Also, if devforum says the size is too big to upload, use this Video Resolution Changer.

Its not the best of videos I dont have a good screen recorder.
robloxapp-20221027-1334009.wmv (497.7 KB)
As you can see the mouse is never in the middle of the block I dont know how to fix it do you know how?

Also sorry you have to download it.

Use OBS (open broadcast software).

What are the Block and Wedge variables? From what I remember, BaseParts don’t have a MouseButton1Click event.

Each part is a model inside it has a MainPart and a block depending on what type of block it is the block is the part so for the wedge model the Block is a wedge part.

And the MouseButton1Click is the TextButtons for each block.

My issue is that the plaement block isnt in the middle of the mouse.

Do you know how I can fix this?
Also sorry you have to download the video.

Maybe try math.round() instead.

local y = math.round(mouse.Hit.Position.Y / 2) * 2 + 1.75
local x = math.round(mouse.Hit.Position.X / 2) * 2
local z = math.round(mouse.Hit.Position.Z / 2) * 2

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.