Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"Attempt to index upvalue 'LocalPlayerName' (a nil value)" How to fix?

I am trying to make a script that creates a folder who's name is the player's name. But it keeps giving me this error: "Attempt to index upvalue 'LocalPlayerName' (a nil value)" Is there a solution for it?

function GetPlayerName(player)
	LocalPlayerName = player
end
game.Players.PlayerAdded:Connect(GetPlayerName)

function MakePlayerFolder()
	local folder = Instance.new("Folder")
	folder.Name = LocalPlayerName.Name
	folder.Parent = game.Workspace.PlayerBuilds
end
MakePlayerFolder()

1 answer

✓ Accepted answer
function MakePlayerFolder(player)
    local folder = Instance.new("Folder")
    folder.Name = player.Name
    folder.Parent = workspace.PlayerBuilds
end
-- in the function above we have the 'player' parameter which allows us to get the player's name.

game.Players.PlayerAdded:Connect(MakePlayerFolder)
-- we call the function inside of the PlayerAdded event which will automatically send its 'player' argument to the function.

This discussion is preserved as it was. New answers, comments, and votes are closed.