The code is supposed to gradually heal the player over time as long as they stand on a designated platform.
Rather than heal in consistent increments, the debouncer keeps failing and allowing a random amount of heals to generate each time the loop restarts.
I have tried a variety of different debouncer techniques, most of which just crash the game outright due to “timeouts.” I have found articles with similar problems, but none of the solutions were related to this problem.
local health = game.ReplicatedStorage.PlayerStats.Health
local Healer = script.Parent
local debounce = true
Healer.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
while health.Value < 100 do
if plr and debounce then
health.Value = health.Value + 1
debounce = false
print("Healed")
else
print("Stop Moving!")
end
wait(5)
debounce = true
end
end)
Try this script put it inside the part the only problem i have with doing this is that the touched event is not accurate as your character cant be static and must be moving in some way even through an animation, It’s like a Venus fly trap.
and the debounce means multiple players cannot heal at once.
function addToHealth(addAmount, humanoid)
local addingToHealth = math.clamp(humanoid.Health+addAmount, 0, 100)
humanoid.Health = addingToHealth
end
local canHeal = true
local waitTime = 4
local part = script.Parent
part.Touched:Connect(function(hitPart)
if not hitPart.Parent:FindFirstChild("Humanoid") then
if not hitPart.Parent.Parent:FindFirstChild("Humanoid") then print('no') return end
end
local humanoid = hitPart.Parent:FindFirstChild("Humanoid") or hitPart.Parent.Parent:FindFirstChild("Humanoid")
if canHeal then
canHeal = false
while humanoid.Health < humanoid.MaxHealth do
addToHealth(25, humanoid)
print('healing ',game.Players:GetPlayerFromCharacter(humanoid.Parent))
wait(waitTime/2)
end
wait(waitTime/2)
canHeal = true
end
end)