How do I detect if part is blocked by object

  1. I would like to figure out how to run things if a object isn’t blocking something
    Example:
    image

  2. What is the issue?

  3. What solutions have you tried so far?
    I’ve asked multiple Developers, tried looking on the devforum.

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local Clone = script.Parent.Folder.Keys
local Clone1 = script.Parent.Folder.AP

local M = false

local AP = nil
local AdorneedDoor = nil

UserInputService.InputBegan:Connect(function(keycode,gp)
	if gp then return end
	if keycode.KeyCode == Enum.KeyCode.F then
		if AdorneedDoor then
			if Clone.Adornee == AdorneedDoor["Non-Tween"].Center then
				AdorneedDoor.Main.RemoteEvent:FireServer()
			end
		end
	end
end)

while wait() do
	for i,v in pairs(game.Workspace.Doors:GetChildren()) do
		if (v["Non-Tween"].Center.Position - Player.Position).magnitude <= 6 then
			Clone.Adornee = v["Non-Tween"].Center 
			Clone.Enabled = true 
			AdorneedDoor = v
			break
		else
			Clone.Adornee = script.Parent.Folder
			Clone.Enabled = false
			AdorneedDoor = nil
		end
	end
end
1 Like

You can use raycasting here. Cast a ray from the torso to 6 studs in front, since that is how far you needed to be to be able to open the door.

2 Likes

Incapaz is right, you should use raycast to detect if part is being blocked.