#Hitting two body parts in one go (custom weapon)

1 messages · Page 1 of 1 (latest)

atomic linden
#

So basically i'm trying to make my custom made weapons and i've noticed that if i hit between two parts of a person, it'll count as if it had hit both and make the players take damage for BOTH the parts that were hit. For example, it removes 20 health for the head and 10 health for the torso, so if i hit between both of these then they take 30 damage instead of 20 or 10. Does anyone have an idea of how to fix it? (Here's the important part of the code that i already made btw)

        if hit.Parent.Parent:IsA("Tool") then
            return
        else
            if hit.Parent:FindFirstChild("Humanoid") then
                if hit.Name == "Head" then
                    fireballClone:Destroy()
                    hit.Parent.Humanoid.Health -= 20
                    print(hit.Name)
                else
                    if hit.Name == "HumanoidRootPart" then
                        return
                    else
                        fireballClone:Destroy()
                        hit.Parent.Humanoid.Health -= 10
                        print(hit.Name)
                    end
                end
            else
                fireballClone:Destroy()
            end
        end
    end)```
celest ginkgo
drifting patrolBOT
#

studio** You are now Level 28! **studio

celest ginkgo
#

i would say to just make a table

#

and put the players name in there

#

and remove it afterwards when trhe fireball is deleted

#

but im assuming you can cast it whilist its still active

#

so i suggest putting a script INSIDE of the fireball instead -- my way of fixing this

#

and doing the damaging there instead with what i said earlier

#

since it would be more easier

#

unless you want to keep it in one script

#

then you have to create clones and make it have different/unique names

#

and have a table that puts the players name, and the parts name aswell

#

and if that specific part hits the player it checks the tables and checks if the player hasnt been hit by that specific part

atomic linden
#

But doesn't that mean that the player couldn't be hit anymore by another fireball afterwards if he's removed from the table?

lethal python
#

You can remove the player from the table after a frame or so

drifting patrolBOT
#

studio** You are now Level 3! **studio

celest ginkgo
#

only if you put the script inside of the fireball that is

#

rather than inside the script

#

cause then it would probably override itself

#

probably

lethal python
#

Basically what you're trying to do here is implementing what's called "i-frames" in games. When a player gets hit, you give them invulnerability time so that they don't get hit again, much like in minecraft.

If you plan on creating another weapon and don't want weapon damage from different weapons stack, you should implement a proper i-frames feature instead.

One way I can think of this, without using a table, is you add a BooleanValue somewhere in the player's character called isInvincible or something similar. Set that to true when the player receives damage, then set it to false after some time, maybe after 0.2 seconds

atomic linden
#

Ooohh so that's what i-frames are

drifting patrolBOT
#

studio** You are now Level 1! **studio

lethal python
#

Or, to make it simpler: instead of a BooleanValue, add a ForceField instance to the player every time they get hit. Same logic, simply remove the ff after 0.2 seconds or so

atomic linden
#

Problem is they both hit the two body parts at the same time (or same frame) so the BooleanValue, for example, is only set to true after they both hit

lethal python
#

The happy path here is this:

  • 2 body parts get hit.
  • You process the first body part hit. Check if isInvincible is true. It is not, so we continue. Take the damage, then set isInvincible to true.
  • Process the second body part hit. Check if isInvincible is true. It is, so we ignore this.
  • After a while, set isInvincible back to false.
celest ginkgo
#

What Kyu said is true tbh i, I almost forgot about the name IF's but, whatever he said, its true.

Although i reccomend doing the ForceField part if your not familiar on how to make "IF's" with Tables / Values Doublethumbs

lethal python
#

Yea that too, I recommend the Forcefield as well so you don't have to keep on checking the boolean value. Roblox will automatically ignore any :TakeDamage() function when a humanoid has a ForceField instance, so you can let roblox do that for you instead

celest ginkgo
#

Although if i remember correctly, it will ignore changing the Health values directly aka.
Humanoid.Health -= 10 or Humanoid.Health = 0

#

but it's the most easiest way out

#

✌️

lethal python
#

Yep. Make sure you use :TakeDamage() if you are using forcefield rather than editing the health value itself

In the case of using a forcefield, this is your happy path:

  • 2 body parts get hit.
  • Process 1st body part hit: use :TakeDamage() to damage player, then give them a forcefield.
  • Process 2nd body part hit: use :TakeDamage(). Since player has forcefield, roblox will internally ignore the :TakeDamage().
  • Remove forcefield after a while