The error : attempt to index upvalue 'player' (a nil value) means that you are trying to use a variable that has not been defined. In this case "player". So you just need to create the player variable by pointing it at the right object in game.Players
I'm assuming that you've got this Script inside a player's model
The player model and humanoid live in game.Workspace
the leaderstats object lives in an object in game.Players
. You need the two to talk to each other.
local playerModel = script.Parent
playerModel.Humanoid.Died:Connect(function()
-- use the player's name to find the player object in game.Players
local playerName = playerModel.Name
local player = game.Players[playerName]
-- update the leaderboard
player.leaderstats.PuzzlePieces.Value = player.leaderstats.PuzzlePieces.Value + 1
end)
Hope this helps
Player
orplayer
? Why are you usingplayer
as upvalue? Shouldn't it be global variable? – Egor Skriptunoff