How to slowly take damage?s

Hello. I want to make it so that every second after you click a part, you take 1 damage. Right now it just instant kills me and idk why. Can someone help please!

local count = 0
local cooldown = 0
script.Parent.TeleportPart1.Transparency = 1
script.Parent.TeleportPart2.Transparency = 1

script.Parent.Door.ClickDetector.MouseClick:Connect(function(plr)
	if count == 0 and cooldown == 0 then
		cooldown = 1
		script.Parent.Sound:Play()
		game.ReplicatedStorage.Teleport:FireClient(plr)
		task.wait(0.5)
		local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
		hrp.CFrame = script.Parent.TeleportPart2.CFrame
		for i = 1, 100, 1 do
			task.wait(1)
			local healthvalue = 100-i
			plr.Character:FindFirstChild('Humanoid'):TakeDamage(healthvalue)
		end
		count = 1
		task.wait(1)
		cooldown = 0
	end
end)
1 Like

Instead of

local healthvalue = 100-i
plr.Character:FindFirstChild('Humanoid'):TakeDamage(healthvalue)

do

plr.Character:FindFirstChild("Humanoid"):TakeDamage(1)

I believe that this should better match what you expect to happen.

Note that the player may regenerate.

1 Like

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