In my game I have attacks that the player uses to fight other players but I can't figure out how to do damage without the script doing the damage constantly instead of once or how to get damage to last over time when touching a part like 5 damage every second for instance. Could anyone point me in the right direction?
COMMUNITY QUESTION
How Would I Make Parts(Attacks) Do Damage?
1 answer
local Part = script.Parent
local Damage = 5
local Seconds = 2 -- Player takes 5 damage every two seconds
local Ticks = 5 -- This determines how many times the Player will take damage
function DAMAGE_PLAYER(humanoid)
humanoid:TakeDamage(Damage)
wait(Seconds)
end
function TOUCHED(hit)
if hit and hit.Parent:FindFirstChild('Humanoid') then
local humanoid = hit.Parent:FindFirstChild('Humanoid')
for ticks = 1, Ticks do
DAMAGE_PLAYER(humanoid)
end
end
end
Part.Touched:connect(TOUCHED)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Provide the script, so we can help. I can't help without it.
that's the thing, I don't have a damage script, that's why I asked for someone to point me in the right direction.
check if a variable is true when the player attacks and if it is false deal damage set variable to true wait(5) and set variable to false again
okay i'll try it out thanks, I'll have to do it later though because I gotta head of for the day.