问题
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:
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
来源:https://stackoverflow.com/questions/56286539/attempt-to-index-upvalue-player-a-nil-value