Roblox default regen doesn't work

I have not modified the Health script in starter character.
We have 2 things, a damage brick and a problematic damage brick.

cool damage brick

Damages the player when touched.
Uses :TakeDamage()
Health Regen works as intended after damage is taken.

problematic damage brick

Damages the player when player can see it.
Uses Tween Service to deal damage.
Health Regen doesn’t work as intended after damage is taken.

Here’s the part of the script where damage is being dealt.

local character = script.Parent.Parent.Character
		local humanoid = character:FindFirstChild("Humanoid")
		local initialHealth = humanoid.Health

		local targetProperties = { Health = humanoid.Health - damage.Value }
		
		local tweenInfo = TweenInfo.new(tweenDuration, easingStyle, easingDirection)
		local tween = TweenService:Create(humanoid, tweenInfo, targetProperties)
		tween:Play()

Does tween service break health regen? Is there an alternative way to deal damage smoothly?

3 Likes

what will tweenservice do to make the damage dealt smoothly?

1 Like


It decreases the health point and makes this easing effect. Also I can set a time length to change how fast the health decreases, it just feels easier.

2 Likes

The only alternative way is to repeatedly call :TakeDamage() or modify the humanoid health.

Typically it’s not recommended to run TweenService on the server side because of its high costs in updating the change to all of the clients in the game. But, if your game is small and it doesn’t cause any unwanted behaviors you should be fine with using it.

2 Likes

Maybe try this:

local REGEN_RATE = 1 / 100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 1 -- Wait this long between each regeneration step.

local LastHealth = Humanoid.Health
local DebHealth = true

local function Regen()
	while Humanoid.Health < Humanoid.MaxHealth and Humanoid.Health > 0 and Humanoid:GetState() ~= Enum.HumanoidStateType.Dead do
		local dt = wait(REGEN_STEP)
		local dh = dt * REGEN_RATE * Humanoid.MaxHealth
		Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
	end
	DebHealth = true
end

local function OnHealthChanged(NewHealth)
	if NewHealth < LastHealth and DebHealth then -- Took Damage
		DebHealth = false
		task.spawn(Regen)
	elseif NewHealth == Humanoid.MaxHealth then
		print("Max Health!")
	end
	LastHealth = NewHealth
end
Humanoid.HealthChanged:Connect(OnHealthChanged)
1 Like

thanks for the reply, I changed the default regen with this script (also linked the var Humanoid to the character’s humanoid). But it doesn’t work :ohmy: I will take a deep look and try to evolve your creation.

2 Likes

is OnHealthChanged being activated? can you use print(NewHealth) under that function.

1 Like

I used spamming :TakeDamage() and oh my god, it still didn’t regen.
d

2 Likes

are you doing this in a localscript? you cant use :TakeDamage on local script, I mean you can, but serverscripts such as health won’t see it.

1 Like

Yeah, It’s a local script. But I can’t use a server script to check if player can see a part. (there’s a proximity prompt in the damage part, I check if it’s shown to player, that’s how I know if someone’s looking at it.)

2 Likes

you should use RemoteEvent:FireServer() to start the health damaging on a serverscript.

:TakeDamaged() works on a localscript but it doesn’t replicate to all players and it doesn’t notice your health differentiation in the “Health” script.

2 Likes

Thanks. I seperated my script into a server and a local one, local script fires a remote event to the server to trigger the damage process. so server does the :TakeDamage part. Thank you again.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.