Humanoid:moveTo working issue

Hey developers!
Today i would like you to help me solve my problem, which is considered to be my fault i guess
I have local script in StarterPlayerScripts, which i want to take control of my Clown NPC’s, here’s what i have written there so far

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)

local Interactables = workspace.Interactables

local Player = Players.LocalPlayer
local Leaderstats = Player:WaitForChild(“leaderstats”)
local TweeningService = game:GetService(“TweenService”)

local WalkInfo = TweenInfo.new(4)

local Clowns = {
[8] = “Carnival”,
[14] = “Pink”,
[16] = “Airballoon”
}

repeat task.wait() until Player.Character ~= nil
repeat task.wait() until Player.Character.Humanoid ~= nil

function AnimateClown(StageNumber)
local Clown = Interactables.Clowns[Clowns[StageNumber]]
local ClownBody : Model = Clown:FindFirstChild(“Rig”)
local ClownHumanoid : Humanoid = ClownBody.Humanoid
local ClownHitBox = Clown:FindFirstChild(“Hitbox”)
local Points : Folder = Clown:FindFirstChild(“Points”)
local Sounds = ClownBody.Sounds
local IdleSounds = Sounds.Idle

local Animations : Folder = Clown.Rig.Animations
local Animator : Animator = ClownHumanoid.Animator

local Sounds = Clown.Rig.Sounds

local WalkingState = true
local HasTarget = false

local function PlayAnimation(AnimationName : Animation)
	local Animation = Animations:FindFirstChild(AnimationName)
	local AnimationTrack = Animator:LoadAnimation(Animation)
	AnimationTrack:Play()
end

local function LoopWalk()
	WalkingState = true
	repeat task.wait(1)
		print("X")
		for i = 1, #Points:GetChildren() do
			ClownHumanoid:MoveTo(Points[i].Position,Points[i])
			ClownHumanoid.MoveToFinished:Connect(function()
				task.wait()
			end)
		end
	until HasTarget
end
LoopWalk()

end

Leaderstats.Stage.Changed:Connect(function()
if Clowns[Leaderstats.Stage.Value] ~= nil then
AnimateClown(Leaderstats.Stage.Value)
end
end)

When my clown has to start working, it is kinda being stuck in place, and moves not constantly, with interuptions or don’t want to walk at all. Help me fix this issue please, can’t find what’s the reason
Here’s little fragment of what is happening

UPDATE: He is working as needed after 8 seconds, so i think i am not doing something right with points restricting him to move in first 8 seconds, i don’t know what

2 Likes

This piece of code is incorrect, what you were trying to do is this:

ClownHumanoid.MoveToFinished:Wait()

This will yield the code until the event MoveToFinished is called, what you did is just execute a task.wait once that event is called, which is obviously not what you’re looking for and you’d just be creating plenty of unusued connections

1 Like

Same issue

Check if any bodyparts of the npc is anchored, then unanchor.

Checked, no unanchored parts in bodies of clowns

Thanks everyone for responding. A friend of mine helped me to figure out that this is problem of cleint-server communication. I should have used copy model from replicated storage, and control that model instead of controlling already created model which is available in server side too.
Take this as consideration for future, hope this will help😀