Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

I need help fixing a poison block. That does damage over time when you touch it. Any Ideas?

Asked by 7 years ago

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)


0
also can someone tell me how to make this shorter? NegativeNil 0 — 7y
0
OH MY LORD WHAT IS THIS CODEEEE INOOBE_YT 387 — 7y
0
You should learn how to use for-loops. XAXA 1569 — 7y

3 answers

Log in to vote
0
Answered by
INOOBE_YT 387 Moderation Voter
7 years ago
Edited 7 years ago

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)

0
Don't Work NegativeNil 0 — 7y
0
I just edited and tested it so it works 100% INOOBE_YT 387 — 7y
0
Sorry I was wrong that did work. Thx' NegativeNil 0 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

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

1
oh btw connect is not deprecated, it just doesn't work properly for some scripts :P have fun greatneil80 2647 — 7y
1
oh btw connect is not deprecated, it just doesn't work properly for some scripts :P have fun greatneil80 2647 — 7y
Log in to vote
0
Answered by 7 years ago

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)
0
I don't know if it matters but the part is Can-Collide false NegativeNil 0 — 7y
0
Btw it didnt work NegativeNil 0 — 7y
0
Did you follow my instructions? hiimgoodpack 2009 — 7y
0
yes NegativeNil 0 — 7y
View all comments (2 more)
0
and what doesnt work exactly? hiimgoodpack 2009 — 7y
0
I don't know... NegativeNil 0 — 7y

Answer this question