I have this placement system pretty laggy but works and i'm woundering why this collision detection isn't working or the part turning red if the some of the part is touching another park located in a folder in the workspace. The placed part goes into a folder named "Buildings" when placed but the collision isn't doing anything at all why?
local script: located in the startergui
game:GetService("RunService").RenderStepped:connect(function() -- Placement System
if Selected then
local X,Z = (Selected.Hitbox.Size.Z/2)%1,(Selected.Hitbox.Size.X/2)%1
local p = CFrame.new(Vector3.new( (Mouse.Hit.x+(grid/2)) - (Mouse.Hit.x+(grid/2))%grid,Mouse.hit.y, (Mouse.Hit.z+(grid/2)) - (Mouse.Hit.z+(grid/2))%grid, Camera.CFrame.p))*CFrame.new(0,0,-0).p
if Toration0 == 0 then X,Z = (Selected.Hitbox.Size.X/2)%1, (Selected.Hitbox.Size.Z/2)%1 end
if Rotation0 == 0 then X,Z = (Selected.Hitbox.Size.X/2)%1, (Selected.Hitbox.Size.Z/2)%1 end
local mouseposition = Vector3.new(X, Z)
local magnitude, nearpoint = math.huge, nil
for _,v in pairs(settings.gridindex) do
for i,z in pairs(v) do
local position = z.position;
local pointmagn = (position.p - mouseposition).magnitude
if (pointmagn < magnitude) then
nearpoint, magnitude = Z, pointmagn
end
end
end
end
if (Selected) then
if (nearpoint.occupied) then
Selected.Hitbox.SelectionBox.Color3 = Color3.new(1, 48/255, 51/255)
end
end
Selected:SetPrimaryPartCFrame(CFrame.new(math.floor(p.X)+X,2.5,math.floor(p.Z)+Z)*CFrame.Angles(0,math.rad(Rotation), math.rad(Toration)))
e

3 comments
Where did you get this from? o.O
?
This is one of the worst ways to make this so I'm not going try to locate the problem but as for your lag change Renderstepped to the mouse.Moved event.