Someone help me with this script

I do not understand why it follows a npc with humanoid but not a player, can someone help me?

[image]

wait(1)

local npc = script.Parent
local torso = npc.Torso
local hum = npc:findFirstChild(“Enemy”)
local humrootpart = npc.HumanoidRootPart
local target = npc.TargetTo

local debounce = false
local punching = false

local SpecialMoves = {
“ShootFireball”,
“BlastFireball”,
“SpeedBoost”,
“Shockwave”,
“Fly”,
“Abyss Power”
}

local larm = script.Parent:FindFirstChild(“Left Arm”)
local rarm = script.Parent:FindFirstChild(“Right Arm”)
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 170
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == “Model”) and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild(“Torso”)
human = temp2:findFirstChild(“Humanoid”)
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos.Position).magnitude < dist then
torso = temp
dist = (temp.Position - pos.Position).magnitude
end
end
end
end
return torso
end

Help us help you, please. This code is impossible to read. It’s not formatted, it’s not in a codeblock, and you’re using variable names like temp. Please make this easier on those willing and able to help you :sweat_smile: You will receive help much quicker if we aren’t immediately turned away by unreadable code!

Please do not post screenshots of code. Instead, format blocks of code by wrapping it in triple backticks (`) like this:

```
– Code
```

1 Like

Sorry it’s from a model I found by tolbox l or modify a little Sorry

[image]

Talves, podrias ver unos tutoriales de :Move() y :MoveTo()

No entiendo bien el problema q estas teniendo. Un “algo” esta siguiendo a un NPC, pero no puedes hacer que ese algo siga a un jugador?
Ese algo es un NPC? Una explicacion mas clara, y como @punyman9 te sugiere, usa el boton </> para insertar codigo y q sea facil de leer

For future posting, explain in a descriptive, informal description of what assistance you need to help. Saying I do not understand why it follows a npc with humanoid but not a player, can someone help me? would be informative and may confuse supporters who are attempting to assist you.

If you clearly don’t understand the code you’ve mentioned, you should read about Loops, Humanoid:Move(), Humanoid:MoveTo(). Like @Dev_Peashie have said earlier, you should be familiar with those Humanoid functions to have a visual of the code you’re lightheaded with.

1 Like

Anyways, don’t use “game.Workspace:children()” to find the list of any models with a humanoid (and humanoid rootpart) inside it, it’ll only find the first layer of the diagram of the explorer view tab, what i mean is that it won’t also detect the model inside a model, you can instead use “game.Workspace:GetDescendants()”.

Anyways, can you show us the whole script? Also you should format it using this, since my cortana button is broken, you can hold alt, press the 9 then 6 on the numpad, forming the symbol `, type that 3 times then write lua after, then you can press enter again and write the code or paste it, then write the 3 symbols again like i instructed earlier or just the </> button, i don’t know i don’t use it.

oh ready thanks oh ready thanks

[image]

1 Like