Hey! I’m scripting NPCs but for some reason Humanoid:MoveTo is not working. Here is the most important snippet of my code:
while true do
wait()
for i,v in ipairs(Titans:GetChildren()) do
local targets = getTargets(v.HumanoidRootPart)
local nearestTarget = getNearestTarget(targets)
print(nearestTarget)
if nearestTarget then
print("yes")
local nearestChar = Players[nearestTarget].Character or Players[nearestTarget].CharacterAdded:Wait()
print(nearestChar)
local nearestHrp = nearestChar.HumanoidRootPart
print(nearestHrp)
followTarget(v.Humanoid, nearestHrp)
end
end
end
It does print everything. Here is the followTarget function
local function followTarget(titanHumanoid, hrp)
print("Moving")
titanHumanoid:MoveTo(hrp.Position, hrp)
end
It does print “Moving” but for some reason it’s not.
How I created the NPC: I played the game and copied my character. Then I pasted it into the game when I stopped. I changed some stuff like the hair and stuff, so that shouldn’t be a problem I guess…
local function makeBigger(humanoid, meters)
local makeBigger = {
humanoid.BodyDepthScale;
humanoid.BodyHeightScale;
humanoid.BodyTypeScale;
humanoid.BodyWidthScale;
humanoid.HeadScale;
}
for i,v in ipairs(makeBigger) do
v.Value = meters
end
end
Copy everything inside of “Animate”, make a new SERVER script called “Animate” and paste everything inside, then if you click play you will get an error about something with emotes, this isn’t a big deal, you can just delete the entire emotes function.
On the server, while having a different NPC and it worked, but in the script it doesn’t, for some reason.
Here is the script:
while true do
wait()
for i,v in ipairs(Titans:GetChildren()) do
local targets = getTargets(v.HumanoidRootPart)
local nearestTarget = getNearestTarget(targets)
print(nearestTarget)
if nearestTarget then
print("yes")
local nearestChar = Players[nearestTarget].Character or Players[nearestTarget].CharacterAdded:Wait()
print(nearestChar)
local nearestHrp = nearestChar.HumanoidRootPart
print(nearestHrp)
v.Humanoid:MoveTo(nearestHrp.Position)
print("Moving")
end
end
end