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

Anti-Team kill script in Weapons?

Asked by 1 year ago

I want to stop Team kill With My sword script, but I can't figure out how to alter my code to check if who I'm hitting is on the same team or not as the person who hits them because it is a different than other Anti team kill scripts, I read that revolve around Humanoid.Health then what I Used TakeDamage().

Here is the Script.

Handle.Touched:Connect(function(Hit)

if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= Tool.Parent then

    if Debounce == true and PlayersHit[Hit.Parent] == nil then

        Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(math.random(15,35))

        PlayersHit[Hit.Parent] = true
        wait(1)
        PlayersHit[Hit.Parent] = nil
    end
end

end)

1 answer

Log in to vote
0
Answered by 1 year ago

I just copied and pasted this code from a model I used earlier

Hope It works

Script:

Tool.Handle.Touched:Connect(function(hit) ----When a victim gets hit by axe
            --This Is optional but I decided to use It just Incase Its a Team vs Team (TvT) game, like brickbattle
            local player1 = game.Players:GetPlayerFromCharacter(hit.Parent)
            local player2 = game.Players:GetPlayerFromCharacter(Tool.Parent)

            if (player1 ~= nil) and (player2 ~= nil) then
                local humanoid = (player2.Character or player2.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")

                if (player1.TeamColor ~= player2.TeamColor) then
                    if (humanoid ~= nil) and CanDamage == true then
                        Sounds.HeadCut:Play()
                        humanoid:TakeDamage(math.random(250,1000))
                        humanoid.Parent.Head:Destroy()
                        CanDamage = false
                    end
                end
            end
        end)
0
Did it work? dradsds 0 — 1y
0
I guess It works imnotaguest1121 362 — 1y
0
I dunno, haven't used the script yet imnotaguest1121 362 — 1y
0
Those variables would not work with my script i think dradsds 0 — 1y
Ad

Answer this question