Thank you to everyone who helped me earlier.
I’m developing a placement system, similar to that of SCP-3008, but I’ve run into a problem.
How can I detect if a block is collided with something and when it stops doing so from the local side?
I just want to know if “SelectionPart” is colliding with something, and also if it stops doing so.
Here’s my local script:
-- /// MAIN LOCALS ///
local LocalPlayer = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local PlrCursor = LocalPlayer:GetMouse()
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StartPlacingEvent = ReplicatedStorage:WaitForChild("Events").StartPlacingEvent
local PlacedEvent = ReplicatedStorage:WaitForChild("Events").Placed
local Orientation = 0
local Distance = 10
local PlayerIsSelecting = false
local NowSelectingName = nil
-- //KEYBINDS//
local PlaceKey = Enum.KeyCode.E
local RotateSidesKey = Enum.KeyCode.R
local RotateUpDownKey = Enum.KeyCode.T
-- /// MAIN LOCAL FUNCTIONS ///
-- Position Updater
local function updateFurniturePosition(furniture)
local HeadPart = LocalPlayer.Character:WaitForChild("Head"):WaitForChild("ModelPart").fpart
local direction = HeadPart.CFrame.LookVector
local newPosition = HeadPart.Position + direction * Distance
furniture.Position = newPosition
end
local function checkCollision(part)
print("Touch grass")
end
-- Tools Functions
local function place()
PlacedEvent:FireServer(NowSelectingName)
print("Place")
end
local function rotateside()
print("RotateSide")
end
local function rotateupdown()
print("RotateUp/Down")
end
------------------------------
-- /// SCRIPT ///
StartPlacingEvent.OnClientEvent:Connect(function(Model)
if PlayerIsSelecting == false then
PlayerIsSelecting = true
print("Selected Model: "..Model.Name)
NowSelectingName = Model.Name
local SelectionPart = Model:WaitForChild("SelectorPart")
if PlayerIsSelecting then
end
for _, part in ipairs(Model:GetDescendants()) do -- Modify model property on Local
if part:IsA("BasePart") then
part.CanCollide = false
part.Transparency = 0.5
part.CastShadow = false
end
end
repeat
task.wait()
for _, part in ipairs(Model:GetDescendants()) do -- Set the Model positions.
if part:IsA("BasePart") then
updateFurniturePosition(part)
end
end
until PlayerIsSelecting == false
else
PlacedEvent:FireServer(NowSelectingName)
PlayerIsSelecting = false
print("What model was selected: "..NowSelectingName)
wait(0.05)
NowSelectingName = nil
end
end)
-- Functions/tools for building
UserInputService.InputBegan:Connect(function(input)
if PlayerIsSelecting == true then
-- Place Function
if input.KeyCode == PlaceKey then
place()
end
-- Rotate at sides Function
if input.KeyCode == RotateSidesKey then
rotateside()
end
-- Rotate up and down sides Function
if input.KeyCode == RotateUpDownKey then
rotateupdown()
end
end
end)
Thanks for any help.