How would i stop regen temporarily when a part is touched?

Basically title.

I’ve tried doing it my self and looking at other forum posts / videos but none have the idea to temporarily disable instead of just completely.

2 Likes

All you have to do is disable then re-enable the script, or a wait

I dont really know this, but how would i do that?

Well it depends how your regen works, but the thing that stays the same no matter what is you will use something along the lines of

script.Disabled = true
wait(1) --Time
script.Disabled = false
1 Like

Assuming you’re talking about the default Roblox regen code, there’s a script inside of each Character when it’s added to the workspace called Health. When touching a part, that’s the script you’d have to disable.

Like this:

local health = 50 -- replace with humanoid health
local disable = false
local part = game.Workspace.Part

local function Touched(hit)
    If hit.Parent:FindFirstChild("Humanoid") then
        disable = true
    end
    disable = false
end

part.Touched:Connect(touched)

while disabled do
    health = health
end

while not disabled do
    health = health + 1
end

You’ll need to use a standalone touch script for the part since a disabled script will cease to run until it’s enabled again.

Inside the part:

script.Parent.Touched:Connect(function(hit)
	local health = hit.Parent:FindFirstChild("Health") --The name of the regen script, which I assume is Health in this example
	
	if health and health:IsA("BaseScript") then
		health.Disabled = true
		task.wait(1) --Replace this with the desired wait time
		health.Disabled = false
	end
end)

Inside the part you could try something like:

local Part = script.Parent

Part.Touched:Connect(function(OtherPart)
	local Target = OtherPart.Parent
	if Target.Humanoid then
		local Health = Target.Health
		Health.Disabled = true
		wait(10) -- however long you want it to disable for
		Health.Diabled = false
	end
end)

or if you want it to stay disabled until they get off the part you could try:

local Part = script.Parent

Part.Touched:Connect(function(OtherPart)
	local Target = OtherPart.Parent
	if Target.Humanoid then
		local Health = Target.Health
		Health.Disabled = true
	end
end)

Part.TouchEnded:Connect(function(OtherPart)
	local Target = OtherPart.Parent
	if Target.Humanoid then
		local Health = Target.Health
		Health.Disabled = false
	end
end)