What is the issue?
Error: Index nil with leaderstats
This is the part of the script that has the issue. “Winners” is a table and I’m trying to get every player from that table and give them the win. It gives the error mentioned above.
for i,v in pairs(Winners) do
Winners[v].leaderstats.Wins.Value += 1
end
A full code sample: local game = script.Parent
local Players = game.Players
local ServerScriptService = game:GetService(“ServerScriptService”)
local ServerStorage = game:GetService(“ServerStorage”)
local ServerStorage = game:GetService(“ServerStorage”)
local Workspace = game:GetService(“Workspace”)
local StarterGui = game:GetService(“StarterGui”)
game.ChildRemoved:Connect(function(child)
if child.Name == “Humanoid” then
child.Parent:Destroy()
end
end
)
function PlayersJoin()
for i,v in pairs(Players:GetPlayers()) do
local player = v
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local Leaderstats = Instance.new(“IntValue”)
Leaderstats.Name = “Wins”
Leaderstats.Parent = leaderstats
Leaderstats.Value = 0
end
end
local function getWinners()
local Winners = {}
for i,v in pairs(game.Players:GetPlayers()) do
if v.PlayerGui:FindFirstChild(“HungerGui”) then
table.insert(Winners, v)
end
end
return Winners
end
function WinGame()
local Winners = getWinners()
for i,v in pairs(Winners) do
local sound = Win:Clone()
sound.Parent = v.PlayerGui
sound:Play()
end
for i,v in pairs(Winners) do
print(v.Name)
Winners[v].leaderstats.Wins.Value += 1
end
for i,v in pairs(Winners) do
v.PlayerGui.HungerGui:Destroy()
v.PlayerGui.WinnerGui.Text = “Winner”
end