I want to make a tycoon game but i want to make it little bit different So i made a placement script where you can place your droppers, upgraders etc. But with raycasting it doesn’t dedect good if its outside of placeable base or if its inside of a another object it dedects it buggy beacuse raycasting only casts like thin stick I need help!
local function CanPlace(targetobject)
local Position = round(Mouse.Hit.Position,4)
local TargetSurface = Mouse.TargetSurface.Name
local SizeY = targetobject.PrimaryPart.Size.Y
local SizeX = targetobject.PrimaryPart.Size.X
local SizeZ = targetobject.PrimaryPart.Size.Z
local Origin = Position + Vector3.new(SizeX/2, SizeY/2, SizeZ/2)
local ignoreTable = {
character,
DropperParts.parts
}
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {ignoreTable}
local RaycastResult = workspace:Raycast(Origin + Vector3.new(0,150,0), Vector3.new(0,-250,0), raycastParams)--Vector3.new(0,-250,0))
local Hightlight = targetobject.Highlight
if RaycastResult and RaycastResult.Instance and RaycastResult.Instance.Parent and
(RaycastResult.Instance.Parent.Parent.Name == "Structures" or RaycastResult.Instance.Parent.Name == "Objects" or not (RaycastResult.Instance.Parent.Name == "Plot")) then
Hightlight.FillColor = Color3.new(1, 0, 0)
Hightlight.OutlineColor = Color3.new(1, 0, 0)
else
Hightlight.FillColor = Color3.new(0, 1, 0)
Hightlight.OutlineColor = Color3.new(0, 1, 0)
end
end