Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

what does it mean by character Upvalue nil value?

Asked by 5 years ago
local Tool = script.Parent

local activated = false

local player = game.Players.LocalPlayer

local character = player.Character



Tool.Activated:Connect(function()

    if activated == false then

        activated = true

        local Humanoid = character:FindFirstChild('Humanoid')

        Humanoid.Health = 100

    end

end)

This keeps on giving me an error : 18:06:37.585 - Players.soccerdeadmatchteam.Backpack.med kit.LocalScript:9: attempt to index upvalue 'character' (a nil value)

1 answer

Log in to vote
1
Answered by 5 years ago

Upvalues

An upvalue is an external local variable; a local variable declared outside of a function body. Here is an example

```lua local var = "abc";

local function fn() --// var is an upvalue here! since it is not declared in this scope end ```

Your issue

The issue with your script is that it ran before the character was even loaded.

The common practice to wait for the character is player.CharacterAdded:Wait()

lua local character = player.Character or player.CharacterAdded:Wait();

Pretty much if the character already is loaded then it will not need to wait. If it is nil it will wait for the character. And then character variable is assigned to the character model.

Ad

Answer this question