Having a LOT of trouble with this script

local part = script.Parent 
local debounce = false

local function IncreaseMaxHealth(hit)
	if debounce then
		return
	end

	if part.Parent:IsA("Accessory") then
		return
	end

	local humanoid = hit.parent:FindFirstChild("Humanoid")
	if humanoid then
		debounce = true
		local CurrentHealth = humanoid.Health
		local CurrentMaxHealth = humanoid.MaxHealth
		print(CurrentMaxHealth)
		if humanoid.MaxHealth >= 100 then
			humanoid.MaxHealth = humanoid.MaxHealth + 10
		else
			humanoid.MaxHealth = humanoid.Health + 10 
		humanoid.Health = humanoid.Health + 10

		while true do
			wait(1)
		if CurrentHealth <= CurrentHealth - 10 then
				CurrentMaxHealth = CurrentMaxHealth - 10
				end
			
		

end

			end
		end

end







part.Touched:Connect(IncreaseMaxHealth)

Lets say you had an max health of 120. i put a print code to print max health but apparently no matter what max health you have, it always counts your max health as 100.

and another question i have is

while true do
			wait(1)
		if CurrentHealth <= CurrentHealth - 10 then
				CurrentMaxHealth = CurrentMaxHealth - 10
				end
			

for now im making it a while true loop just to even make sure it works AND it doesnt. Im really stumped and I know i’ve probably made a mistake somewhere here but i dont know where.

1 Like

Correct me if im wrong, did you mean by when the player touches a part. The maxhealth increase follow with a health?

yeah just to fill in the time it needs to regen

Can you clearly state what exactly you want to happen in the context of this code?

A couple of observations.

You set debounce to true but never set it back to false so the event is only ever going to run once.

if CurrentHealth <= CurrentHealth - 10 then

This is never going to resolve to true