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

How would I make an area attack do damage to players over time?

Asked by 6 years ago
Edited 6 years ago

I have a part that has CanCollide == false and Anchored == true. I want it so that when a player is inside the part(in the area of effect), they will take damage every 1 second or so. I've tried multiple ways of going about this but they seem to never work. Is there a special way of doing this, can anyone help me out? Also, this has to do damage to multiple players over time not just one.

2 answers

Log in to vote
0
Answered by 6 years ago

If you already have a working script, you're going to want to create layers so that when the player moves through it they take damage, or a loop that damages any players within it for a certain amount of time. the loop, based on your question, should be wait(1).

0
Yes I know that it needs to be a loop for damage but I dont know how I would start making that bit of code. Wolf5429 15 — 6y
0
Decide to use the onion layering system. Make thin layers, as the player animation will, if the player remains there, make them touch a new layer if they just stand there. Attempt to make thin sheets in the Y axis and either X or Z. This way a player using R6 will suffer as much adage as one using R15. just my ten cents. billybobRAE 41 — 5y
Ad
Log in to vote
0
Answered by
uhTeddy 101
6 years ago

I made a script to put in the part, it has issues with it and doesn't work much but here it is.

local Settings = {
    ['TimeWait'] = .2, -- How long per run
    ['Damage'] = 5, -- Damage per Run
}


local using = false

script.Parent.Touched:Connect(function(part) -- Part Touched
    if game:GetService("Players"):GetPlayerFromCharacter(part.Parent) then -- Checks if the part is a player
        if not using then
            if part.Name == "Left Leg" or part.Name == "LeftFoot" or part.Name == "HumanoidRootPart" then
                using = true
                print("Using")
                local humanoid = part.Parent:WaitForChild("Humanoid")
                while using do
                    humanoid.Health = humanoid.Health - tonumber(Settings.Damage)
                    wait(tonumber(Settings.Damage))
                end
            end
        end
    end
end)

script.Parent.TouchEnded:Connect(function(part)
    if game:GetService("Players"):GetPlayerFromCharacter(part.Parent) then -- Checks if the part is a player
        if part.Name == "Left Leg" or part.Name == "LeftFoot" or part.Name == "HumanoidRootPart" then
            if using then
                using = false
                print("Not Using")
            end 
        end
    end
end)
0
Is there any simpler way of doing this? Also, this looks like a script to use during one touch of the part not a script for a part that needs to to damage over time. Wolf5429 15 — 6y
0
It does kill over time uhTeddy 101 — 6y
0
Well either way, I just tried the script and it doesn't work for my part for some reason. Wolf5429 15 — 6y

Answer this question