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

Can you stop a function while a tool is activated?

Asked by 9 years ago

I want to stop a takedamage function while the tool I have is activated.I didn't make the script yet, I just want to know if it's possible.Bassicaly I want this:

Player = script.Parent.Parent.Parent
c = Player.Character
debounce = true
if debounce == true then
    if c.Humanoid:TakeDamage == true then --Here's what I am interested in
        c.Humanoid:TakeDamage = false
    end
end

Is it possible?

0
Well, you could just make yourself god (MaxHealth = math.huge() and Health = 9e9) General_Scripter 425 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

humanoid:TakeDamage is a function, not a property. This means that you cannot assign it a value.

If it wasn't a Roblox function, you would be able to overwrite it with a blank function so that if a script called it, it wouldn't do anything - but you aren't allowed to do that for functions in Roblox objects.

The easiest way to prevent a humanoid from taking damage is to add a ForceField (though if a script uses "humanoid.Health = humanoid.Health - damage" instead of "humanoid:TakeDamage(damage)", the forcefield will be ignored).

Otherwise, you need to add, say, a BoolValue (ex with name "Invincible") that all other weapons/scripts must check for before dealing damage. If they find the BoolValue, they must not damage the character.

As UndeniableLimited suggests, you could make the character have tons of health until the effect wears off, and then you could restore their original health/maxhealth.

A fourth method is to listen for humanoid.Changed events and if the 'health' property has decreased, then put it back to where it was. If the health was at 0, this means the player died, which might mess up other scripts (ex a leaderboard that keeps track of kills), and you'd have to perform character:MakeJoints() to try and keep them alive (I haven't tested this; I saw it recommended by someone else in a different thread)

Ad

Answer this question