I am working on a building system for a survival game where you can only place objects on parts or terrain. I am using :BlockCast() because :GetPartsInPart() and .Touched don’t work with terrain. However, I am having issues with this system because it is having issues detecting anything, whether it is a basepart or terrain. It seems to be based on position and rotation of the hitbox. Whenever the hitbox is touching something, it should always detect it and the hitbox should turn green. I think the problem is that the :BlockCast() is not always casting or it’s in the wrong position but I don’t know how to fix it. I have also tried sphere casting but it’s giving me the same problem.
Here is video demonstrating my problem (when the box flashes red its not detecting anything)
Here is the code to the script for creating the hitbox for detection (local script):
local function ObjectPreview()
local pos = mouseRaycast()
if not destroyed then
mouse.TargetFilter = object
Snap(pos) -- function for grid snapping
object:SetPrimaryPartCFrame(CFrame.new(PosX,PosY,PosZ)*CFrame.Angles(0,math.rad(rotationY),0))
local rayparams = RaycastParams.new()
rayparams.FilterType = Enum.RaycastFilterType.Include
rayparams.FilterDescendantsInstances = {game.Workspace}
local blockcast = game.Workspace:Blockcast(hitbox.CFrame,hitbox.Size,hitbox.CFrame.LookVector,rayparams)
if blockcast then
canplace = true
else
canplace = false
end
--for the object preview
hitbox.CanCollide = false
for i, Aobject in pairs(previewmodel:GetChildren()) do
Aobject.Transparency = 0.5
Aobject.CanCollide = false
end
--for the outline color of the object (shown in video)
if canplace then
selectionBox.Color3 = Color3.new(0,1,0)
selectionBox.SurfaceColor3 = Color3.new(0,2,0)
else
selectionBox.Color3 = Color3.new(1,0,0)
selectionBox.SurfaceColor3 = Color3.new(2,0,0)
end
end
end