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

[Solved]Why is this script erroring with an attempt to index a nil value?

I received help on this problem earlier and it helped sort of. Here is the code and error:

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)
-- in another script
	local plrName = plr.Name
	local plrInfo = game.ServerStorage:FindFirstChild(plrName):WaitForChild("PlayerInfo") -- this is what is erroring and I have no idea why, because it works in the playerremoving script. please help me understand what is going wrong.
-- the error is: "ServerScriptService.BoxDroppingScript:36: attempt to index a nil value"

Please help

1 comment

0

Give us the entire script please.

1 answer

A Local Script can't access ServerStorage, only regular scripts can. Instead, use ReplicatedStorage, both local and server scripts can access it.

Server script:

game.Players.PlayerAdded:Connect(function(plr)
        local plrFolder = Instance.new("Folder", game.ReplicatedStorage)
        plrFolder.Name = plr.Name
        local plrInfo = Instance.new("Folder", plrFolder)
        plrInfo.Name = "PlayerInfo"
end)

Local Script:

 local plrName = plr.Name
 local plrInfo = game.ReplicatedStorage:WaitForChild(plrName):WaitForChild("PlayerInfo")

1 comment

0

But I am not trying to access it through a local script

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