1
votes

please help me! I am making a game but i keep running into the same problem

i tried many things but nothing worked


script.Parent.Humanoid.Died:Connect(function()
    print("yeet")
    player.leaderstats.PuzzlePieces.Value =  player.leaderstats.PuzzlePieces.Value + 1
end)
1
Player or player? Why are you using player as upvalue? Shouldn't it be global variable?Egor Skriptunoff
can you right the script down? i don't understand what you meanabdtou 7175

1 Answers

1
votes

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