Title explains it all. I know how to use the ClickDetector and how to input a function, but I don't know how I would make a function that damages the player every 2 or so seconds. Can someone help and explain to me what I need to use?
local clickdetector = script.Parent.ClickDetector clickdetector.MouseClick:Connect(function(plr) repeat wait(0.1) plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - 1 until plr.Character.Humanoid.Health == 1 end)
When it makes it damage you every 2 seconds the player heals so it's not possible to get to the goal, so I changed it.
Make sure this is a server script inside the click detector.
local clickDetector = script.Parent clickDetector.MouseClick:Connect(function(player) --get the player by writing a parameter within the function local character = player.Character local humanoid = character.Humanoid if not humanoid.Health > 0 then --if player is not alive then stop the script return end repeat --repeats whatever is under the loop until given condition is met which is in this case when the humanoid's health is 1 humanoid:TakeDamage(1) --you can change the damage here wait() --you can change the rate of damage here until humanoid.Health == 1 end)