Character:MoveTo() function not working in a method of an Object

I cannot seem to understand why the character is not moving to the location passed to the MoveTo() function.
Here is my code:

function GetLocation(self)
	if RS:IsClient() then
		local WorldName = self.WorldName
		local Location = self.Position
		local VirtualWorldsAdded = workspace.VirtualWorlds:GetChildren()
		local PositionFound = false
		local Player = game.Players.LocalPlayer
		local Character = Player.Character or Player.CharacterAdded:wait()
		for _,v in pairs(VirtualWorldsAdded)do
			if v.Name == WorldName then
				for _,child in pairs(v:GetChildren())do
					if child.Name == Location then
						print("PositionFound")
						PositionFound = child.Position
						Character:MoveTo(child.Position)
					end
				end
			end
		end
	end
end

i know that the position is found as i printed out the PositionFound variable and a vector3 value as expected was outputted. However, the character is just not being moved to the required position. Any assistance will be greatly appreciated. :slight_smile:

Does SetPrimaryPartCFrame work? Using this you can also specify the orientation.

I got it work thanks anyway for your suggestion.

Please close your topic if that’s the case.

If you found the solution, please add it to the replies and mark it as the solution. This will allow others to learn too. Have a good day.

The script wasn’t working because i called the method before the character was fully loaded into the workspace

.

1 Like