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!
I want the enemy npc to track down only players but not other npcs -
What is the issue? Include screenshots / videos if possible!
My script does not work the enemy npc only stands still and not move at all -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have found a post really similar to my script but when i tried transferring the script over to my script it didnt work
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is my script:
local NPC = script.Parent
local debounce = false
NPC.NPCHumanoid.Touched:Connect(function(hit)
if hit and game.Players:GetPlayerFromCharacter(hit.Parent) and NPC.NPCHumanoid.Health > 1 then
if debounce == false then
debounce = true
hit.Parent.Humanoid:TakeDamage(25)
wait(.25)
debounce = false
end
end
end)
function FindPlayer(Position)
local playerList = game:GetService(“Players”):GetChildren()
local Torso = nil
local Distance = 50
local HumanoidRootPart = nil
local Humanoid = nil
local Player = nil
for i, plr in pairs(playerList) do
local playerCharacter = plr.Character or plr.CharacterAdded:Wait()
if playerCharacter then
HumanoidRootPart = playerCharacter:FindFirstChild("HumanoidRootPart")
Humanoid = playerCharacter:FindFirstChild("Humanoid")
if (HumanoidRootPart ~= nil) and (Humanoid ~= nil) and (Humanoid.Health > 0) then
if (HumanoidRootPart.Position - Position).Magnitude < Distance then
Torso = HumanoidRootPart
Distance = (HumanoidRootPart.Position - Position).Magnitude
end
end
end
end
end
while true do
wait(1)
local Target = FindPlayer(script.Parent.HumanoidRootPart.Position)
if Target ~= nil then
script.Parent.NPCHumanoid:MoveTo(Target.Position, Target)
end
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Forgive me if I am unclear with responses given as I am still a new developer and some of the code that I found was from the internet so I may not understand it myself