Humanoid:MoveTo never moves humanoid or times out

Hello,

I’m trying to get a clone of the local player to walk in a loop inside of a viewport frame. The goal is to show off a trail accessory in a gui before the player decides to wear it. The clone of the player shows up in the viewport frame just fine and its idle animations work.

The issue comes when I try to use Humanoid:MoveTo(). I’ve checked in the Explorer tab and the clone’s WalkToPoint gets updated, but the clone doesn’t move and MoveToFinished never fires, even after 8 seconds.

I’ve looked around on the DevForum and haven’t seen anything that has helped me fix this issue. I’m thinking that this is related to the fact that the humanoid is the child of a WorldModel inside of a Viewport inside of a GUI. Is there any way to get around this?

Here’s the script that handles the clone.

local View = script.Parent

local PlayersService = game:GetService("Players")

-- ensure that player character is loaded
local Players = game:GetService("Players")
game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

local function clonePlayerCharacter(character)
	character.Archivable = true
	local clone = character:Clone()
	character.Archivable = false
	return clone
end

--check for camera and create new instance if needed if needed
local function validateVpCam()
	local vpCamera = View:FindFirstChild("vpCamera")
	if not vpCamera then
		vpCamera = Instance.new("Camera")
		vpCamera.Parent = View
		View.CurrentCamera = vpCamera
	end
	return vpCamera
end

--check for world model and instance new if needed
local function validateWorldModel()
	local worldModel = View:FindFirstChild("WorldModel")
	if not worldModel then
		worldModel = Instance.new("WorldModel")
		worldModel.Parent = View
	end
	return worldModel
end

--look for old character model and remove if there
local function clearOldClone()
	local oldChar = View.WorldModel:FindFirstChild("PlayerClone")
	if oldChar then
		oldChar:Destroy()
	end
end

local function validatePath()
	local path = {
		A = Vector3.new(0,0,0),
		B = Vector3.new(3,0,4),
		C = Vector3.new(6,0,0),
		D = Vector3.new(3,0,-4)
	}
	return path
end

-- make clone walk endlessly
local function cloneLoop(clone, path)
	-- clone starts off at A, so move to B
	print(path)
	print("trying to move to B...")
	clone.Humanoid:MoveTo(path.B)
	clone.Humanoid.MoveToFinished:Wait()
	print("trying to move to C...")
	clone.Humanoid:MoveTo(path.C)
	clone.Humanoid.MoveToFinished:Wait()
	print("trying to move to D...")
	clone.Humanoid:MoveTo(path.D)
	clone.Humanoid.MoveToFinished:Wait()
	print("trying to move to A...")
	clone.Humanoid:MoveTo(path.A)
	clone.Humanoid.MoveToFinished:Wait()
end

-- main function that drives the viewport display
local function updateCharacterViewport()
	
	local vpCamera = validateVpCam()
	local worldModel = validateWorldModel()
	clearOldClone()

	local PlayerClone = clonePlayerCharacter(Character)
	
	PlayerClone.Name = "PlayerClone"
	PlayerClone.Parent = worldModel
	PlayerClone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	PlayerClone.HumanoidRootPart.Anchored = false
	PlayerClone:PivotTo(CFrame.new(Vector3.new(0,0,0)))
	
	--make camera face PlayerClone
	vpCamera.CFrame = CFrame.new(PlayerClone.HumanoidRootPart.Position - Vector3.new(0, 0, 8)) * CFrame.Angles(0, math.rad(180), 0)
	-- make PlayerClone walk endlessly to show off trail
	local path = validatePath()
	cloneLoop(PlayerClone, path)
end

updateCharacterViewport()

1 Like

Hi mate i had a similar issue with my horror game however i removed the Movetofinish: wait and just added a normal wait with the time it would take to get there for example wait (3) and it work fine with no issue :+1:

1 Like

I see what your trying to do but, I think even if you fix it, the trail wont show in the viewport due to its limitation to visual effects. About the problem, idk, i have the same one, Humanoid just doesnt move with Humanoid:MoveTo(position)

1 Like

I believe this is because physics are not simulated in Viewports. MoveTo() moves the character physically.

I tested the script out but instead of using MoveTo(), I set the CFrame, which works because modifying CFrames do not physically move it. I also tested the same script but the character is in workspace, which also works fine.

1 Like

Thanks for the response :slight_smile: I tried this out but it didn’t work, probably because I’m trying to move my character inside ViewportFrame / WorldModel

Thanks for testing that out! I was thinking the same thing about the lack of physics being an issue. It definitely works in the Workspace. I might try using the CFrame and just using different idle animations to show off the trail.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.