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

how do i make code that slowly does damage to a plyr, when they r in it?

Asked by 4 years ago

Here is a script that slowly does damage while the player is in it. Unfortunately it doesn't work all the time. I put it in a block and put the blocks down different places so when the player walks through it it does damage.

~~~~~~~~~~~~~~~~~

local damage = 1 local touched local timebeforeotherdamage = 1

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if touched == false then
              touched = true
        repeat
     if touched == true then
        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage

end
wait(timebeforeotherdamage)
        until
        hit.Parent.Humanoid.Health == 0
        end

    end
    repeat
    wait()
    until
    touched == false





end)
script.Parent.TouchEnded:Connect(function(hit)
    touched = false
end) ~~~~~~~~~~~~~~~~~

sometimes it will do a little damage, but when you go out of the block and back in, it does A LOT. The code looks fine to me so I don't know whats wrong...

0
Use FindPartsInRegion3 (https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3) instead, it is way more reliable in this situation. Benbebop 1049 — 4y
0
I will just warn you guy I'm still learning, so talk to me like a 5 year old astonplep 32 — 4y
0
A region3 is made by specifying the top right and bottom left points of the box you want to do damage in. Once you have the region made, you can find parts in it and do damage to the humanoid. SteamG00B 1633 — 4y
0
I would highly suggest Region3s, to learn how to get players in a Region3, a good example is AlvinBlox's Robbable Bank Tutorial, which includes the use of region3s. Nckripted 580 — 4y
0
ok astonplep 32 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This might work! Put this in a script inside of your damage part. Change the wait(1) to change how many seconds you want to wait in between damaging. Change the hum:TakeDamage(50) to how much damage you want to do. If this doesn't work or gives an error, tell me in the comments of this answer and I'll fix my code.

local part = script.Parent
local debounce = false
part.Touched:Connect(function(touched)
    local hum = touched.Parent:FindFirstChild("Humanoid") --if its a player
    if hum then
        if debounce == false then
            hum:TakeDamage(50) --Damage you want to do
            wait(0.5) --wait whatever amount of seconds
            debounce = true
        end
    end
end)

**EDIT: you can make it the part's transparency 1 and cancollide false to make it sort of an invisible "damage zone"

Make sure it's a server script and inside of your part. Hope this works :)

0
That didn't work astonplep 32 — 4y
0
Errors? proqrammed 285 — 4y
0
yes astonplep 32 — 4y
0
as a server script do you mean a normal script, and it didn't work when you stoped moving astonplep 32 — 4y
View all comments (2 more)
0
He's asking for the errors, not if you got errors. SteamG00B 1633 — 4y
0
no errors astonplep 32 — 4y
Ad

Answer this question