Hey developers.
Before I begin, I would like to mention that yes, I have searched through similar posts, and no, none of them were helpful.
Anywho, I’m having some struggles with a script that makes a humanoid move.
local wt = script.WalkType
local char = script.Parent
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
task.wait(2)
local function walkTick()
if wt.Value == "Wander" then
local mv = Vector3.new(hrp.Position.X + math.random(-40,40), 0, hrp.Position.Z + math.random(-40,40))
if mv == Vector3.new(hrp.Position.X, 0, hrp.Position.Z) then
return 0
end
print("oh we movin")
script.Parent.Humanoid:MoveTo(mv)
task.wait()
script.Parent.Humanoid.MoveToFinished:Wait()
task.wait(math.random(1,10))
return {}
end
end
while task.wait() do
local s, e = pcall(function()
local call = walkTick()
end)
if not s then
warn(e)
end
end
This here is the script. The value mentioned on lines 1 & 9 is always set to “Wander” without change (I plan to have some NPCs have different movement behaviors).
Here’s what’s even stranger though: the script works sometimes.
5/6 of the time, the script works just fine.
On the off 1/6 of the time, the script “works”. Sure, it prints “oh we movin” as mentioned on line 16, but it doesn’t actually move the humanoid.
I’ve tried several things:
Did you make sure all of the parts were unanchored?
Yes.
Did you look at tutorials?
Sure did (none of them were helpful).
Did you check that the Vector3 is not the same as the current humanoid root part’s position?
dude.
So yea. Any help would be much appreciated. I am very confused by this issue.