I am trying to make and script an NPC system where they would attack players when they got near, but I dont know how to do that. Does anybody have any advice, like scripts or directions?
So, you need to get your NPC model first. Define it in your script like you have done already.
local NPC = script.Parent
local Humanoid = script.Parent:FindFirstChild(“Humanoid”)
local HRP = script.Parent:FindFirstChild(“HumanoidRootPart”)
Next you want to make a function which gets the player closest to the NPC.
local function GetClosestPlayer(range)
local List = {}
local Target = nil
for i, v in pairs(game.Players:GetPlayers()) do
local dist = v:DistanceFromCharacter(HRP.position)
…
Do consider searching on the forum
1 Like
Okay, I will do that. Thanks for your help.