Working on this beginner guide on scripting: https://developer.roblox.com/en-us/onboarding/scoring-points/2
Either I am messing up this code or the guide is wrong? LOL.
The error is: ServerScriptService.Script:19: attempt to get length of a nil value
This script is supposed to create the leaderboard with a category for points, and add 1 point to each individual player every second for as long as they stay alive.
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
end
Players.PlayerAdded:Connect(onPlayerAdded)
while true do
wait(1)
local playerList = Players:GetPlayers()
for currentPlayer = 1, #playerlist do
local player = playerList[currentPlayer]
local points = player.leaderstats.Points
points.Value = points.Value + 1
end
end

1 comment
Line 19 by the way