So I made a very simple placement system that literally just places objects along a 2x2 grid. No rotation or collision. My problem is I want to detect collision between objects and then set a variable so you can't place the object. My localScript is in a GUI in StarterGui. I tried to detect collision with the Touched and TouchEnded events but that did not work. I tried those events in a Script and in the localScript I am using for placement. Here is my current code: Note > I am just placing a single part that is not even in a model.
-- Player Variables
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
-- Position Variables
local PosX
local PosY = 2.1
local PosZ
-- Object Variables
local Gui = script.Parent
local Button = Gui.TextButton
local Baseplate = workspace.Baseplate
local Texture = Baseplate.Texture
local Model -- This is going to be a part
-- Textures
local GridId = "rbxassetid://13786085"
-- Snap to grid Variables
local Grid = 2
local Snap = 2
local Rounding = 0.5
-- Debounce
local IsPlacing = nil
-- functions
-- Snaps the part to a grid
local function Round()
PosX = math.floor(Mouse.Hit.X / Snap + Rounding) * Grid
PosZ = math.floor(Mouse.Hit.Z / Snap + Rounding) * Grid
end
-- Moves the part
local function Movement()
if IsPlacing == true and Model:IsA("Part") then
Round()
Model.Position = Vector3.new(PosX, PosY, PosZ)
end
end
-- Places the object
local function Placement()
if IsPlacing == true and Model:IsA("Part") then
local FinishedModel = Model:Clone()
FinishedModel.Parent = workspace.Clones
FinishedModel.CanCollide = true
Model:Destroy()
IsPlacing = false
Texture.Texture = ""
end
end
-- Starts the placement
local function StartPlacement()
Model = game.ReplicatedStorage.Movement:Clone()
Model.Parent = workspace
Model.CanCollide = false
Texture.Texture = GridId
IsPlacing = true
Mouse.Move:Connect(Movement)
end
Button.MouseButton1Click:Connect(StartPlacement)
Mouse.Button1Down:Connect(Placement)
Thanks for the help!

2 comments
Thanks I will check that out!
No problem