alright so i have my placement system and it works like this you bring out the tool and then you get a model in front of you keep in mind all of its descendants are noncollidable and that model moves in front of you BUT you can place things inside of other things and on top of players which is not what i want what im wanting is you can only place the object if nothing is colliding with it except terrain ground or a supporting object(foundation)
LocalScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
-- note to self make sure tool is not requires handle
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Hitbox = nil
local Mouse = Player:GetMouse()
local Shack = ReplicatedStorage:FindFirstChild("Shack")
local PlayerGui = Player:WaitForChild("PlayerGui")
local Backpack = Player:WaitForChild("Backpack")
local LookAtCamera = PlayerGui:WaitForChild("LookAtCamera")
local Spot = Instance.new("Vector3Value")
local Twist = Instance.new("Vector3Value")
local debounce = false
local CanPlace = Backpack:WaitForChild("CanPlace")
Tool.Equipped:Connect(function()
local ShackClone = Shack:Clone()
ShackClone.Parent = workspace
ShackClone.Name = "ShackBluePrint"
LookAtCamera.Disabled = false
Hitbox = ShackClone.CenterPart
while wait(.02) do
if ShackClone then
local loc = Head.Position + (Head.CFrame.lookVector * 12)
local x = loc.x
local y = loc.y
local z = loc.z
ShackClone:SetPrimaryPartCFrame(CFrame.new(x,y,z))
ShackClone:SetPrimaryPartCFrame(lookAt(Head.Position, Vector3.new(Hitbox.CFrame.Position.X,Head.Position.Y,Hitbox.CFrame.Position.Z)))
-- lookAt(Head.Position,Hitbox.CFrame.lookVector)
Spot.Value = Hitbox.Position
Twist.Value = Hitbox.Orientation
local results = GetTouchingParts(Hitbox)
if #results >= 1 then
for x = 1, #results do
for i,v in pairs(ShackClone.Parts:GetChildren()) do
local ray = Ray.new(Hitbox.CFrame.Position,Hitbox.CFrame.upVector.Unit * -9)
local part, position = workspace:FindPartOnRay(ray, v, true, false)
if (not results[i]:IsDescendantOf(ShackClone)) then--and results[x].Name ~= v.Name and results[x].Name ~= "CenterPart" and part then
v.Color = Color3.fromRGB(25, 129, 219)
CanPlace = true
else
v.Color = Color3.fromRGB(250,0,0)
CanPlace = false
end
end
end
end
end
end
end)
Tool.Unequipped:Connect(function()
workspace.ShackBluePrint:Destroy()
LookAtCamera.Disabled = true
CanPlace = false
end)
Tool.Activated:Connect(function()
if CanPlace == true then
local PositionClicked = Spot.Value --Mouse.hit.p
local RotatedPosition = Twist.Value
if Mouse.Target.Name == "Shack" or Mouse.Target.Name == nil then
else
local posX, posY, posZ = PositionClicked.X, PositionClicked.Y, PositionClicked.Z
game.ReplicatedStorage.PlaceFabrication:FireServer("Shack",posX, posY, posZ,RotatedPosition)
end
--Tool:Destroy()
end
end)
function lookAt(target, eye)
local forwardVector = (eye - target).Unit
local upVector = Vector3.new(0, 1, 0)
local rightVector = forwardVector:Cross(upVector)
local upVector2 = rightVector:Cross(forwardVector)
return CFrame.fromMatrix(eye, rightVector, upVector2)
end
function GetTouchingParts(Part)
local connection = Part.Touched:Connect(function() end)
local results = Part:GetTouchingParts()
connection:Disconnect()
return results
end
i provided the full script so i wouldnt be asked later to provide more of the script the ShackClone has a main part called CenterPart and the rest of its Parts inside of a model named Parts
UPDATE-- i swapped the lines on 43,44 with 46,47 and now it almost works but sometimes it shows up as blue and red at the same time (some parts of the ShackClone will be red other blue) and you can still place it while its doing that
