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
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.