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

How do I add to the players health?

this is my script to try but I cant find out how to add to the players health?

local UserInputService = game:GetService("UserInputService")
local debounce = false
local heal = 50
UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		local name = game.Players.LocalPlayer
		local player = game.Workspace:FindFirstChild(name.Name)
		player.Humanoid.MaxHealth = 125
		player.Humanoid.Health + heal
	end)

2 comments

0

try setting player.Humanoid.Health to itself like player.Humanoid.Health = player.Humanoid.Health + heal

0

Instead of "player.Humanoid.Health + heal" you can do "player.Humanoid.Health += heal"

1 answer

simple use "+="

local UserInputService = game:GetService("UserInputService")
local debounce = false
local heal = 50
UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.R then
        local name = game.Players.LocalPlayer
        local player = game.Workspace:FindFirstChild(name.Name)
        player.Humanoid.MaxHealth = 125
        player.Humanoid.Health += heal
    end)

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