I am trying to make a placing block system where it places on other blocks based on where the player puts their mouse on a face. But there’s a problem, sometimes it doesnt place on the correct face and I need to be like under 25 degrees of facing the face where I want to place the block, if I try to place on like 85 degrees for bridging for example, it places it completely the wrong way or doesn’t even register where the player placed a block on. Here is the local script that gets the placement:
UserInputService.InputBegan:Connect(function(input, gameProcessed)
local hand = camera:FindFirstChild("Hand")
if gameProcessed or not hand then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
mouseIsDown = true
if input.UserInputType == Enum.UserInputType.Touch then
local now = tick()
if now - lastTapTime <= doubleTapThreshold and lastTarget then
local mousePos = UserInputService:GetMouseLocation()
local unitRay = workspace.CurrentCamera:ScreenPointToRay(mousePos.X, mousePos.Y)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {localPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 1000, raycastParams)
if raycastResult then
local normal = raycastResult.Normal
local pos = raycastResult.Position
local cf = CFrame.new(pos, pos + normal) * CFrame.Angles(math.rad(-90), 0, 0) * CFrame.new(0, 0.5, 0)
remoteEvent:FireServer("PlaceBlock", hand.Position, lastTarget, localPlayer.Inventory.SelectedSlot.Value, normal, cf)
end
end
lastTapTime = now
end
if lastTarget then
remoteEvent:FireServer(lastTarget, hand.Position)
else
if not swingLoopRunning then
swingLoopRunning = true
task.spawn(function()
while mouseIsDown and not lastTarget and not miniBlockTarget do
remoteEvent:FireServer("None", hand.Position)
task.wait(0.3)
end
swingLoopRunning = false
end)
end
end
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
rightMouseIsDown = true
if lastTarget then
local mousePos = UserInputService:GetMouseLocation()
local unitRay = workspace.CurrentCamera:ScreenPointToRay(mousePos.X, mousePos.Y)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {localPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 1000, raycastParams)
if raycastResult then
local normal = raycastResult.Normal
local pos = raycastResult.Position
local cf = CFrame.new(pos, pos + normal) * CFrame.Angles(math.rad(-90), 0, 0) * CFrame.new(0, 0.5, 0)
remoteEvent:FireServer("PlaceBlock", hand.Position, lastTarget, localPlayer.Inventory.SelectedSlot.Value, normal, cf)
end
end
elseif input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Q then
remoteEvent:FireServer("DropBlock", hand.Position, lastTarget, localPlayer.Inventory.SelectedSlot.Value)
end
end)