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

How would I implement an anti-team kill feature into my script?

Asked by
Duksten 20
7 years ago
Edited 7 years ago

I have this script for a hand axe that I'm making for a game, so far it works perfectly fine. Each time it hits a humanoid it deals damage. However I also want it so that it wont deal any damage to any of the player's team mates, and I have tried using GetPlayerFromCharacter however I am having trouble on figuring out how to use it in my code when the script detects that a humanoid has hit the handle.

Here is the snippet of my code that fixates on hit detection.

01local canDamage = true
02canChop = true
03Tool.Handle.Touched:connect(function(hit)
04    if not swinging then return end
05    if not canDamage or not canChop then return end
06 
07    function damage()
08        canDamage = false
09        hit.Parent:FindFirstChild("Humanoid"):TakeDamage(26)
10        Tool.Handle.FleshHit:Play()
11        wait(coolDown2)
12        canDamage = true
13    end
14 
15    local function chop()
View all 34 lines...
0
No need to do "var == false", or "var == true", you can use "var" and "not var". Programical 653 — 7y
0
thanks made some few minor edits to the code that i posted Duksten 20 — 7y

2 answers

Log in to vote
0
Answered by
gitrog 326 Moderation Voter
7 years ago

Alright, I'm going to give you the code for it. So, you'll need to check TeamColors when it does damage. We can do this using GetPlayerFromCharacter. Before the Humanoid takes damage, you'll want to check the player's TeamColor.

01function damage()
02       canDamage = false
03   if hit.Parent:FindFirstChild("Humanoid") then
04       local player = game.Players:GetPlayerFromCharacter(hit.Parent)
05       local user = game.Players:GetPlayerFromCharacter(Tool.Parent)
06       if player then
07           if player.TeamColor == user.TeamColor then
08               --penalties for teamkilling
09           else
10               hit.Parent.Humanoid:TakeDamage(26)
11           end
12       end
13   end
14       Tool.Handle.FleshHit:Play()
15       wait(coolDown2)
16       canDamage = true
17   end
Ad
Log in to vote
-1
Answered by 7 years ago

Before your damage script you can check if the person you are hitting is the same TeamColor or not, if they are then make damage 0, if not make the axe do 26 damage.

0
Good job explaining.. bad job providing what you explain in code. Goulstem 8144 — 7y
0
Maybe he could have elaborated more, but I'm not sure the dude should've had to code for him. AdministratorReece 193 — 7y
0
I'm not going to code for him. Shadowthaumaturge 97 — 7y

Answer this question