I have a very simple placement script and so far the objects can collide with parts. I need help preventing that.
LocalScipt
local BuildingCF = CFrame.new()
local PlaceObject = game.ReplicatedStorage.Events.PlaceBuilding
local mouse = game.Players.LocalPlayer:GetMouse()
local FakeBuilding = game.ReplicatedStorage.Spawnables.Buildings.FakeBuilding
mouse.TargetFilter = FakeBuilding
local Snap = 1
local shouldBeFiring = true
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("ImageButton") then
local button = v
v.MouseButton1Click:Connect(function()
shouldBeFiring = true
FakeBuilding.Parent = workspace
if shouldBeFiring == true then
mouse.Move:Connect(function()
BuildingCF = CFrame.new(
math.floor(mouse.Hit.X / Snap + 0.5) * Snap,
1,
math.floor(mouse.Hit.Z / Snap + 0.5) * Snap
)
FakeBuilding:SetPrimaryPartCFrame(BuildingCF)
end)
end
mouse.Button1Down:Connect(function()
if shouldBeFiring == true then
PlaceObject:FireServer(BuildingCF, button)
shouldBeFiring = false
end
if shouldBeFiring == false then
FakeBuilding.Parent = game.ReplicatedStorage
end
end)
end)
end
end
Script
local PlaceObject = game.ReplicatedStorage.Events.PlaceBuilding
PlaceObject.OnServerEvent:Connect(function(player, BuildingCF, button)
local building = game.ReplicatedStorage.Spawnables.Buildings[button.Name]:Clone()
building:SetPrimaryPartCFrame(BuildingCF)
building.Parent = workspace
building.Main.BrickColor = player.TeamColor
end)