Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
2ndwann 131
4 years ago

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

Log in to vote
1
Answered by
Elixcore 1337 Moderation Voter
4 years ago
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.
Ad

Answer this question