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

How would I make this script damage the player only once?

I'm trying remake a boss, with one script for several boss attacks instead of a script that disables or enables several other scripts.

Problem is that mine one-shots the player when it touchs them.

function Slash2() --Huge slash
local e = workspace.Guard.HugeSlash
e.Touched:connect(function(hit)
	if hit.Parent~=nil then
	if hit.Parent:findFirstChild'Humanoid' then
	hit.Parent.Humanoid:TakeDamage(28)
	hit.Parent.Torso.Velocity=push.CFrame.lookVector * 200 -- PUSH THE CASUL.
	end
	end
end)
end

The other attack is identicle to this function, with the exception of the "e" variable.

1 comment

0

Try using using a debounce

1 answer

As AviatorJake said a debounce would work. Now I would assume two things when you mean only do it once. Either once in a call of a event or just once. For my sake I will script both.

Only damage once

local damage  = true --- Makes the script wait

function Slash2() --Huge slash
if damage == true then -- Checks if it is true
local e = workspace.Guard.HugeSlash
e.Touched:connect(function(hit)
    if hit.Parent~=nil then
    if hit.Parent:findFirstChild'Humanoid' then
    hit.Parent.Humanoid:TakeDamage(28)
   damage = false -- Permanently prevents the script from doing damage again
    hit.Parent.Torso.Velocity=push.CFrame.lookVector * 200 -- PUSH THE CASUL.
      end
    end
    end
end)
end


Only damage once a time

local damage = true

function Slash2() --Huge slash
if damage == true then
local e = workspace.Guard.HugeSlash
e.Touched:connect(function(hit)
    if hit.Parent~=nil then
    if hit.Parent:findFirstChild'Humanoid' then

    hit.Parent.Humanoid:TakeDamage(28)
    damage = false
    hit.Parent.Torso.Velocity=push.CFrame.lookVector * 200 -- PUSH THE CASUL.
   wait(2)
   damage = true --- This then allows the script to do damage again
    end
    end
    end
end)
end

If this helped don't forget to accept. If you have any question I would be glad to help. Thanks for the question!

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