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

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

Asked by 6 years ago
Edited 5 years ago

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

0
Give us the entire script please. ThatPreston 354 — 6y

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

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")
0
But I am not trying to access it through a local script User#21908 42 — 6y
Ad

Answer this question