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

Trying to make a Ray Cast ignore the players armor. So that it still damages the player on hit?

Asked by 6 years ago
Edited 6 years ago

I have had this bug for 3-4 days now and I keep pushing it back hoping one day it will pop into my head on how to fix it, but I cant. So I have come here!

I have a gun script and I am trying to make it so when it hits a players armor of something it still damages them, and ive thought of using a ray cast ignore and that is what I am trying right now but there has to be other ways also right?

Like this has to be over complicated just to damage a player when the armor is hit.

Like a Stormtrooper has a full helmet, so if he gets hit in the head it stops the bullet so they are immune to head shots. I dont want this.

But here are the scripts, theses are just some chunks of code out of the whole thing.

This is the local script

function RayCast(Start,Direction,Range,Ignore)
    local Hit,EndPos = game.Workspace:FindPartOnRay(Ray.new(Start,Direction*Range),Ignore)
    if Hit then
        if (Hit.Transparency > 0.75
            or Hit.Name == "Handle"
            or Hit.Name == "Effect"
            or Hit.Name == "Bullet"
            or Hit.Name == "Laser"
            or string.lower(Hit.Name) == "water"
            or Hit.Name == "Rail"
            or Hit.Name == "Arrow"
            or (Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Humanoid.Health == 0)
            or (Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("TEAM") and TEAM and Hit.Parent.TEAM.Value == TEAM.Value))
            or (Hit.Parent:FindFirstChild("Humanoid") and PiercedHumanoid[Hit.Parent.Humanoid]) then
            Hit,EndPos = RayCast(EndPos+(Direction*.01),Direction,Range-((Start-EndPos).magnitude),Ignore)
        end
    end
    return Hit,EndPos
end

There is the ray for the local script now here is the damage portion

        local Hit,EndPos = RayCast(Start,Direction,5000,Character)
        if not Module.ExplosiveEnabled then
            if Hit and Hit.Parent then
                local TargetHumanoid = Hit.Parent:FindFirstChild("Humanoid")
                local TargetTorso = Hit.Parent:FindFirstChild("UpperTorso")
                --local TargetTEAM = Hit.Parent:FindFirstChild("TEAM")
                if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
                    --if TargetTEAM and TargetTEAM.Value ~= TEAM.Value then
                        InflictTarget:FireServer(TargetHumanoid,
                                                TargetTorso,
                                                (Hit.Name == "Head" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage,
                                                Direction,
                                                Module.Knockback,
                                                Module.Lifesteal,
                                                Module.FlamingBullet)
                        PiercedHumanoid[TargetHumanoid] = true
                    --end
                else
                    PierceAvailable = 0
                end
            end

That fires the server and here is the server side damage script

InflictTarget.OnServerEvent:connect(function(Player,TargetHumanoid,TargetTorso,Damage,Direction,Knockback,Lifesteal,FlamingBullet)
    if Player and TargetHumanoid and TargetHumanoid.Health ~= 0 and TargetTorso then
        while TargetHumanoid:FindFirstChild("creator") do
            TargetHumanoid.creator:Destroy()
        end
        local creator = Instance.new("ObjectValue",TargetHumanoid)
        creator.Name = "creator"
        creator.Value = Player
        game.Debris:AddItem(creator,5)
        TargetHumanoid:TakeDamage(Damage)
        if TargetHumanoid.Health <= 0 then
            game.ReplicatedStorage.DataFile[Player.Name].AssaultClassKills.Value = game.ReplicatedStorage.DataFile[Player.Name].AssaultClassKills.Value + 1
        end
        if Knockback > 0 then
            TargetTorso.Velocity = Direction * Knockback
        end
        if Lifesteal > 0 and Humanoid and Humanoid.Health ~= 0 then
            Humanoid.Health = Humanoid.Health + (Damage*Lifesteal)
        end
        if FlamingBullet then
            local Debuff = TargetHumanoid.Parent:FindFirstChild("IgniteScript") or script.IgniteScript:Clone()
            Debuff.creator.Value = Player
            Debuff.Disabled = false
            Debuff.Parent = TargetHumanoid.Parent
        end
    end
end)

I know it a ton to take it but I will be so thankful if someone can please help me out. I just cant seem to fix this problem.

Thank you for your time. Merry Christmas!

Answer this question