Stop and Restart Health regeneration when Player touches different Parts

So basically I want to stop the health regeneration of a player when they touch Part A but only continue healing after touching Part B. I tried doing the opposite of the health script by removing a health point per second. However, they script only minus the health of a player like 5 times because I have not added a debounce yet cause I am afraid multiple players land on it at once and some would evade the stopping for health regeneration. I have tried looking devforum about this but only found posts regarding the delaying of health regeneration so far. Of course I am not asking you to write the entire script for me but tell me what I should use to achieve my goal

The script:

script.Parent.Touched:Connect(function(hit)
	local tb = 0
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		tb = 1
		while tb == 1 do
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1
			wait(1)
			if game.Workspace.NoRegenLand.RestartRegen and hit.Parent:FindFirstChild("Humanoid") then
				tb = 0
				break
			end
		end
	end
end)

So what types of script or function should I use?

1 Like

There’s a script called Health in the player’s character, disable/enable it when you want them to regenerate or not.

But where do I put the script under as I want regeneration to comeback if the player touches another part or dies. Also the health script is under a model in studios

You can just disable the script, it will stop the regen, vice versa.

Here’s an example:

local Players = game:GetService('Players')
local Part = script.Parent

Part.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	if Player then
		local Character = Player.Character
		if Character then
			local Health = Character:FindFirstChild('Health')
			if Health then
				-- disable / enable.
			end
		end
	end
end)
2 Likes

The health script is in a model in Workspace and I have tried identifying it by doing:

local player = game.Players.LocalPlayer.Name
game.Workspace.player:WaitForChild("Health")

even though it is in there, I was not able to use the above to identify it

Look at my reply.

EDIT: Works fine for me.

1 Like

Thank you for your help, it is working now.

1 Like