I’m trying to create a custom placement system with barriers that try to prevent an object from being placed, but some how no method I’ve tried works.
I’ve tried detecting inside boundaries, using “GetTouchingParts,” but these either only work outside the barrier or don’t work at all.
In this image, I try to use the “GetTouchingParts” method but nothing really happens, I can still place the object inside the barrier.
Here is the source code for the script:
local mouseRay = Mouse.UnitRay
local castRay = Ray.new(mouseRay.Origin,mouseRay.Direction * 1000)
local Ignore = {Prop,game.Players.LocalPlayer.Character}
local hit,position = workspace:FindPartOnRayWithIgnoreList(castRay,Ignore)
if hit ~= nil and position ~= nil then
local CFAngles = CFrame.Angles(0,math.rad(Rotation),0)
local CF = CFrame.new(position.X,position.Y+Prop.Size.Y/2,position.Z)
for _, i in pairs(workspace.Propables.Barriers:GetChildren()) do
if i:GetTouchingParts() == Prop then
ApprovedToPlace = false
TweenService:Create(Prop,TweenInfo.new(0.5),{Color = Color3.fromRGB(227, 25, 62)}):Play()
end
end
local Distance = (Mouse.Hit.p-Player.Character.HumanoidRootPart.Position).Magnitude
if Distance < PlacingRange then
ApprovedToPlace = true
TweenService:Create(Prop,TweenInfo.new(0.5),{Color = Color3.fromRGB(36, 227, 122)}):Play()
TweenService:Create(Prop,TweenInfo.new(0.05),{CFrame = CF * CFAngles}):Play()
else
ApprovedToPlace = false
TweenService:Create(Prop,TweenInfo.new(0.5),{Color = Color3.fromRGB(227, 25, 62)}):Play()
end
end
Please, if anyone can help, thank you.
EDIT: Video of the bug happening: