it is on the dev forum! Theres even some explanation articles.
However
local character = player.Character or player.CharacterAdded:Wait() -- this tells it to wait for the character added even if player.Character is nil
character:MoveTo(Pos)
Should work but will stop the script waiting for a character
You should create a variable for the Character. Itâs not sure whether if a character exist or not. Otherwise, it can error some time. Just like what @Bellyrium said. However, it will wait until the Character is found, causing the script to delay a bit.
It seems to find the Character now, If i print the variable âcharacterâ it gives me the player name.
But it doesnât move the character. It seems that it skip that line.
local character = Player.Character or Player.CharacterAdded:Wait()
print(character) --Prints the player name
character:MoveTo(game.Workspace.Part.Position) --Seems ignored
print("Moved") --Gets printed
try adding a small delay before it moves? Also I think you might have to add something like Character:WaitForChild("HumanoidRootPart").Anchored = false to assure the humanoid doesnât mess with it much. Anchored parts can cause issues and I think it needs the root part to move.
â CFraming scripts and whatnot can also set a character back to where they came from. Is there anything else affecting the character movement?
I honestly donât use :MoveTo() much⌠So I donât really know what may be wrong. I am assuming you want the placement feature of the positioning instead of using a cframe?
The issue is happening because you are trying to access the Character property of the Player before it is available. The Character is loaded in asynchronously, so you need to wait for it before attempting to use it. You can do this by using a WaitForChild function:
local Main = script.Parent.Parent
local Player = game.Players:FindFirstChild(Main.Name)
local Character = Player:WaitForChild("Character")
Character:MoveTo(game.Workspace.Land.Position)
local Main = script.Parent.Parent
local Player = game.Players:FindFirstChild(Main.Name)
local Character = Player.Character
repeat
wait()
until Character
Character:MoveTo(game.Workspace.Land.Position)
so both of those are just replies without reading the thread�
WaitForChild() Wont workâŚ
Iâll test out :MoveTo() on a character. I think you might need to wait for the full appearance to load for a character too tbh!
player.CharacterAppearanceLoaded:wait() -- or something similar should wait for the character to be done loading and not just 'in the workspace'
-- can bug out though
this line doesnât work, but I added a delay of 3 seconds and it worked!!!
Thank you a lot for helping me out of this, and sorry for stressing you so much
The error message âattempt to index nil with âMoveToââ suggests that the value of Player.Character is nil . This means that Player does not have a character at the time that this script is run.
There are a few reasons why this might be the case:
The player does not have a character yet. This can happen if the player has just joined the game and their character has not finished spawning yet.
The player has left the game. In this case, the Player object will still exist, but it will not have a Character property.
There is a typo in the name of the player. Make sure that Main.Name is the correct name of the player that you want to move.
To fix this issue, you can add a check to make sure that the player has a character before trying to move it:
local Main = script.Parent.Parent
local Player = game.Players:FindFirstChild(Main.Name)
if Player and Player.Character then
Player.Character:MoveTo(game.Workspace.Land.Position)
end
You can also use WaitForChild to wait for the Character property to be added to the player object, but you should set a timeout to avoid waiting indefinitely:
local Main = script.Parent.Parent
local Player = game.Players:FindFirstChild(Main.Name)
local character = Player:WaitForChild("Character", 5) -- wait for up to 5 seconds
if character then
character:MoveTo(game.Workspace.Land.Position)
end