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

Why does this kill people I use "IF" with to ignore?

Asked by 8 years ago

I edited the default linkedrocket, and it works perfectly, it doesn't kill soldiers, and kill enemies and ignores players. But here's when it gets complicated. When I hit an enemy and kill/damage it, the explosion damages/kills any other soldier or player in the vicinity! It's a really annoying bug! I'll leave a bold message in the script to tell you where I THINK the error is. Btw, this is part of the rocket script.

function blow(hit)
    Hit = hit
    plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    local explosion = Instance.new("Explosion")
    explosion.DestroyJointRadiusPercent = 0 -- neck welds won't be destroyed
    explosion.BlastRadius = 20
    explosion.BlastPressure = 1000

        local maxDamage = 100       

        local explosion = Instance.new("Explosion")
        explosion.DestroyJointRadiusPercent = 0 -- neck welds won't be destroyed
        explosion.BlastRadius = 20
        explosion.BlastPressure = 1000

        explosion.Hit:connect(function(hitPart, partDistance)
        local humanoid = hitPart.Parent and hitPart.Parent:FindFirstChild("Humanoid")
        local plr = game.Players:GetPlayerFromCharacter(hitPart.Parent)
    if hit.Parent.ClassName ~= ("Tool") and hit.Parent.Name ~= ("Workspace") and humanoid and  hit.Parent.Name ~= ("Soldier")  not plr then
            swoosh:stop()
            local distance_factor = partDistance / explosion.BlastRadius    -- get the distance as a value between 0 and 1
            distance_factor = 1 - distance_factor
    if hit.Parent.ClassName ~= ("Tool") and hit.Parent.Name ~= ("Workspace") and hit.Parent.Name ~= ("Soldier")                -- flip the amount, so that lower == closer == more damage **HERE**
            humanoid:TakeDamage(maxDamage*distance_factor)   **HERE**
    else                **HERE**
            explosion = Instance.new("Explosion") HERE
            explosion.DestroyJointRadiusPercent = 0 **HERE**
    end   -- 0: no damage; 1: max damage
    elseif hit.Parent.ClassName ~= ("Tool") and hit.Parent.Name ~= ("Workspace") and plr and plr.TeamColor ~= game.Teams.Enemies.TeamColor then
            swoosh:stop()
            explosion = Instance.new("Explosion")
            explosion.DestroyJointRadiusPercent = 0
    end
end)
0
This code has a syntax error. Have you read the output? / Bold doesn't work in code blocks. Just say the line numbers. BlueTaslem 18071 — 8y

Answer this question