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

How do I fix the error: "plrName is not a valid member of ServerStorage"?

Here is the code:

game.Players.PlayerAdded:Connect(function(plr)
	
	local plrFolder = Instance.new("Folder", game.ServerStorage)
	plrFolder.Name = plr.Name

	local plrInfo = Instance.new("Folder", plrFolder)
	plrInfo.Name = "PlayerInfo"
end)



game.Players.PlayerRemoving:Connect(function(plr)

	local plrName = plr.Name
	local plrInfo = game.ServerStorage.plrName.PlayerInfo -- here is where the error occurs

end)

Could someone please help me figure out what is wrong? Thank you.

1 comment

0

ServerStorage[plrName].PlayerInfo?

2 answers

✓ Accepted answer

Rather use FindFirstChild or [plrName]

game.Players.PlayerAdded:Connect(function(plr)

    local plrFolder = Instance.new("Folder", game.ServerStorage)
    plrFolder.Name = plr.Name

    local plrInfo = Instance.new("Folder", plrFolder)
    plrInfo.Name = "PlayerInfo"
end)



game.Players.PlayerRemoving:Connect(function(plr)

    local plrName = plr.Name
    local plrInfo = game.ServerStorage:FindFirstChild(plrName):WaitForChild('PlayerInfo')

end)

Also, the second param of instance.new (parent) is deprecated

game.Players.PlayerAdded:Connect(function(plr)

    local plrFolder = Instance.new("Folder")
    plrFolder.Name = plr.Name
	plrFolder.Parent = game.ServerStorage

    local plrInfo = Instance.new("Folder")
    plrInfo.Name = "PlayerInfo"
    plrInfo.Parent = plrFolder
end)



game.Players.PlayerRemoving:Connect(function(plr)

    local plrName = plr.Name
    local plrInfo = game.ServerStorage:FindFirstChild(plrName):WaitForChild('PlayerInfo')

end)

2 comments

0

Thank you

0

Np :)

Use [] brackets instead of the . dot operator:

game.Players.PlayerAdded:Connect(function(plr)

    local plrFolder = Instance.new("Folder", game.ServerStorage)
    plrFolder.Name = plr.Name

    local plrInfo = Instance.new("Folder", plrFolder)
    plrInfo.Name = "PlayerInfo"
end)



game.Players.PlayerRemoving:Connect(function(plr)

    local plrName = plr.Name
    local plrInfo = game.ServerStorage[plrName].PlayerInfo

end)

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