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

How do I have a projectile pass through players and still do damage to NPC humanoids?

Asked by 5 years ago

My friend and I have a projectile that is fired to the cursor location on a key press but when the orb passes through yourself it does not do damage to the enemy on the other side

0
script pls User#23365 30 — 5y
0
Add a conditional statement to your script that checks if they're NPC, if it is, do damage. If it's not, don't deal the damage User#24403 69 — 5y
0
how does the projectile move?, by BodyMovers, CFrames or its just a Raycast User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Assuming quite heavily that your orb works a lot like the rocket launchers in Roblox, here's your fix. To let your "orb" pass through players, I recommend that you change the collision group and only allow the "enemy" collision group to be able to collide with the "orb."

Here's a link to a useful tutorial on using collision groups: https://www.robloxdev.com/api-reference/class/PhysicsService

Also, on the script side of things, I would recommend you to use an "if" statement to check whether it collided with a player or an enemy. Here's a sample:

orb = script.Parent

orb.hit:Connect(function(WhateverItHit)
    if WhateverItHit:FindFirstChild("Humanoid") then
        --I guess you could leave this blank or set it to "if not WhateverItHit ... then..." and you will be able to not require to put in an elseif statement.
    elseif WhateverItHit:FindFirstChild("Enemy") then
        --The "Enemy" can just be the NPC "Humanoid" renamed to "Enemy".
    end
end)

If you have any questions or issues, please contact me. ;)

Ad

Answer this question