Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

what does it mean by character Upvalue nil value?

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

✓ Accepted answer

Upvalues

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

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()

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.