I am trying to make a block that will do damage to you over time, but the problem is every time you touch it will speed up the damage. Can someone tell me whats wrong?
function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) h.Health = h.Health -2 wait(1) end end script.Parent.Touched:connect(onTouched)
I wrote this without testing so there might be some problems.
local Enabled = true script.Parent.Touched:Connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") and Enabled == true then Enabled = false repeat wait(0.2) Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health - 2 until Hit.Parent.Humanoid.Health <= 0 Enabled = true end end)
Okay.... lets start Step 1. Make a brick Step 2. Insert a localscript in that brick or a script... Step 3. Paste this:
----Made by greatneil80---- wait(1) -- wait for the player's service to load while wait() do -- a loop.... local part = script.Parent -- or the poison brick part :P local plr = game:GetService("Players").LocalPlayer -- the player local humanoid = plr.Character.Humanoid -- i'm requesting to get the character ;-; if humanoid then -- if the humanoid is even a thing then................ script.Parent.Touched:connect(function() -- if player touches the brick :P repeat -- keep repeating until they have one life humanoid.Health = Humanoid.Health - 1 wait(1) -- how long before poison hits the player until humanoid.Health == 1 end) -- add the ends... end -- change to end) if end doesn't work, it should work though because it ain't a function end -- change to end if end) doesn't work
Thanks for using, I hope this works :) feel free to accept answer
What you should do, is have a BoolValue in Player module in workspace to tell if it is poisoned or not. I'm gonna pretend it is named Poisoned.
script.Parent.Touched:Connect(function(hit) --:connect is deprecated, you should use :Connect if hit.Parent:FindFirstChild('Humanoid') then if not hit.Parent.Poisoned.Value then hit.Parent.Poisoned.Value = true for i = 1, 50 do hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 2 wait(1) end hit.Parent.Poisoned = false end end end)