Right now, I have created a tool that, when activated, gives the player 10 health. However, a second after giving the player the health, it takes it away. Does anyone know why this is the case? It is a localscript placed inside a tool named "Food"
local tool = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character
local healAmount = 10
function onActivated ()
print("Hello")
local currentHealth = char.Humanoid.Health
local newHealth = currentHealth + healAmount
char.Humanoid.Health = newHealth
end
script.Parent.Activated:Connect(onActivated)

6 comments
Due to filtering enabled, localscripts can't and won't interact with the game (i.e. other players won't be able to see the modifications your localscript made)
I'd suggest for you to do the script in a serverscript instead.
This is what I suspected, but when I copy paste the code into a serverscript, I get this error.
Workspace.Food.Script:3: attempt to index nil with 'Character' - Server - Script:3
You can't use LocalPlayer inside of a server script. Instead, try checking for the tool's parent inside of the function to get the character.
The localscript will only heal the player on their screen, but for the others the player is not healed to them