You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Make an NPC “see and detect” a player, and get their username.
What is the issue? Include screenshots / videos if possible!
I’m out of ideas on how to do something like this
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried making a part for the npc’s vision but then the npc can see you through walls.
I also tried searching on YouTube for tutorials and didn’t find anything
If anyone can let me know of a service or a technique of making detection like Notoriety or Assassin’s Creed I appreciate it! I do have an already made way of a restricted area, for detecting if the npc should attack or not
hey! i recently made a detection system. although this uses parts and not players, you can refactor this code to work with players and NPCs.
local LookPart = workspace.Look
local Part = workspace.Part
while task.wait() do
local Dot = (LookPart.Position - Part.Position).Unit:Dot(LookPart.CFrame.LookVector)
if Dot > 0.7 then
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params:AddToFilter({LookPart,Part})
local Raycast = workspace:Raycast(LookPart.Position,-(LookPart.Position - Part.Position).Unit * (LookPart.Position - Part.Position).Magnitude,Params)
if not Raycast then
print("Found")
end
end
end
basically, the “lookpart” is the part that detects another specific part. it doesn’t work with players, but you can definitely use this code to work for players with a few adjustments.
i changed the code for you to hopefully work for players.
local LookPart = workspace.Look
while task.wait() do
for _, Player in pairs(game.Players:GetPlayers()) do
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Dot = (LookPart.Position - HumanoidRootPart.Position).Unit:Dot(LookPart.CFrame.LookVector)
if Dot > 0.7 then
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params:AddToFilter({LookPart,Character:GetChildren()})
local Raycast = workspace:Raycast(LookPart.Position,-(LookPart.Position - HumanoidRootPart.Position).Unit * (LookPart.Position - HumanoidRootPart.Position).Magnitude,Params)
if not Raycast then
print("Found")
end
end
end
end