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
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")