Still have questions? Join our Discord server and get real time help.
0

# How Would I Make Parts(Attacks) Do Damage?

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?

0
Provide the script, so we can help. I can't help without it. User#19524 170 — 2y
0
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. Wolf5429 15 — 2y
0
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 justoboy13 153 — 2y
0
okay i'll try it out thanks, I'll have to do it later though because I gotta head of for the day. Wolf5429 15 — 2y

0
hellmatic 1502
2 years ago
Edited 2 years ago
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)