Attempt to perform arithmetic (add) on nil and number

local function AddScore(player, scoreType, score)
	print(PlayerScoresTable[player]) -- prints tabe
	print(PlayerScoresTable[player][scoreType]) -- prints nil
	PlayerScoresTable[player][scoreType] = PlayerScoresTable[player][scoreType] + score
end

function PlayerManager:SetupPlayerScores()
	for _, player in pairs(Players:GetPlayers()) do
		PlayerScoresTable[player] = {Points = 0, Kills = 0, Deaths = 0}
	end
end

-- Fires when player gets kill
AddScore(player, 'Kill', 1)
2 Likes

If this prints nil:

print(PlayerScoresTable[player][scoreType])

Surely it’s because your array looks like this?

PlayerScoresTable[player] = {Points = 0, Kills = 0, Deaths = 0}

You passed ‘Kill’ but your array has ‘Kills’. Could this be the reason?

So the easiest and most logical solution would be to change the ‘Kill’ argument to ‘Kills’

-- Fires when player gets kill
AddScore(player, 'Kills', 1) -- Changed to Kills from Kill
1 Like