Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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).

2 comments

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.

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.

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)

3 comments

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.

0

It does kill over time

0

Well either way, I just tried the script and it doesn't work for my part for some reason.

This discussion is preserved as it was. New answers, comments, and votes are closed.