So I have some problems with this script, what I want to do is make this NPC only find humanoid that’s not belong to a player.
Can anyone show me what should I do or just explain what is wrong with it?
I did not make this script.
for i, v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Model") and (not Creator or (Creator and v ~= Creator.Value)) then
local character = v.Character
local humanoid = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso")
local TorsoDistance = (torso.Position - Torso.Position).magnitude
if humanoid and humanoid.Health > 0 and torso and TorsoDistance <= ClosestTorsoDistance then
--Scripts
One way to do it would be to use GetPlayerFromCharacter
local Players = game:GetService("Players")
for i, v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Model") and (not Creator or (Creator and v ~= Creator.Value)) then
local character = v.Character
local isPlayer = Players:GetPlayerFromCharacter(character)
if not isPlayer then -- the character was not found in the playerlist so isn't a player
local humanoid = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso")
local TorsoDistance = (torso.Position - Torso.Position).magnitude
if humanoid and humanoid.Health > 0 and torso and TorsoDistance <= ClosestTorsoDistance then
end
end
end
end
--Scripts