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)
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 ```
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.