Error in script.. | How can i fix

i am keep getting this error…

with everything i tried with HumanoidRootPoint too instead of name…
how can i fix? heres the script

game.Players.PlayerAdded:Connect(function(plr)
print("Player joined!")
plr.CharacterAdded:Connect(function(char)
	print("Char added")
	local gOccupied = game.Workspace.Green.Occupied.Value
	if gOccupied == false then
		gOccupied = true
		print(char.Parent.Name)
    end)
 end)

I want to check char’s name
and i tried that in ServerScriptService too…

Any ideas?

What are you trying to do? It think it looks like you are trying to get the player’s name. You can simply just do player.Name

Bruh no, i want to get Char’s name because i am doing moveto stuff…

Try this, print(char.Parent), we need see what’s their parent.

Couldn’t you just do char:MoveTo(...) then?

image

showing the same error “Attempt to index nil with :moveto”

Ah, I see. Your char parent is nil. try print(char).

or should i try
game.workspace[plr.Name]:moveTo()?

You only use the MoveTo: function on the character’s humanoid, not the char’s name.

You have to call it on char, not char.Parent.

char.Parent is just going to be the workspace, or nil if the character hasn’t fully loaded in yet.

If it doesn’t work, try this:

game.Players.PlayerAdded:Connect(function(plr)
print("Player joined!")
plr.CharacterAdded:Connect(function(char)
if char then
	print("Char added")
	local gOccupied = game.Workspace.Green.Occupied.Value
	if gOccupied == false then
		gOccupied = true
		print(char.Parent.Name)
            end
    end)
 end)

everything i putting it keeps giving me same error

By the way, the MoveTo: function only works with the character’s humanoid.

thanks it worked! thank u so much, i will make this solution

You have a direct reference to the player’s character. It is the char variable that is passed through the CharacterAdded event. You don’t need to “search” the workspace for the player’s name. You already have the character.

i put only print(char) and it worked

2 Likes