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

How do I PREVENT Team Killing?

Asked by 6 years ago
Edited 6 years ago

This is my script, it's for killing & animating.

local CanAttack = true
local sound = script.Parent.Sound





script.Parent.Activated:connect(function()

local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Crowbarhit2)



if CanAttack == true then

attack:Play()
sound:Play()

CanAttack = false

wait(1)

attack:Stop()
sound:Stop()

CanAttack = true> 

script.Parent.CanDamage.Value = true

end

end)

[SECOND ONE]

local sound4 = script.Parent.Sound4
script.Parent.blade.Touched:connect(function(p)
  if script.Parent.CanDamage.Value == true then
   p.Parent.Humanoid:TakeDamage(25)
    sound4:Play()
   script.Parent.CanDamage.Value = false
  end
end)

but It works, but I don't know how to make it so no Teamkilling happens.

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

For this you would use the function “GetPlayerFromCharacter()” of the players service.

—blade touch
local hitPlayer = game.Players:GetPlayerFromCharacter(p.Parent)
canAttack = hitPlayer.Team ~= LocalPlayer.Team
if canAttack then
      —kill script
end
0
Not sure if I'm doing this right, but I put this I think where you said to ItsRechintech -5 — 6y
0
But it did not work ItsRechintech -5 — 6y
0
In between line 2 and 3 of second script NexanianStudios 91 — 6y
0
I posted what I did to "fix it" but it didn't work, could you elaborate on where to add it in the script? ItsRechintech -5 — 6y
View all comments (7 more)
0
Whoops, change “canAttack” to “canDamage” NexanianStudios 91 — 6y
0
Also, did you make localplayer a variable that has the local player in it? NexanianStudios 91 — 6y
0
Oh wait, should I be using a localscript? For this I was using a script? It says consider changing it to local, I'm not a scripter, I don't have one for my game ATM, so I'm kind of improvising ItsRechintech -5 — 6y
0
I'll post the new one that's still not working below. ItsRechintech -5 — 6y
0
Since its a tool, at the beginning, set the player to script.Parent.Parent NexanianStudios 91 — 6y
0
My script isn't functioning, could you edit your post and just post the fixed one for me? If so thanks :) ItsRechintech -5 — 6y
0
Nexanian? It doesnt work...// local sound4 = script.Parent.Sound4 local player = script.Parent.Parent script.Parent.blade.Touched:connect(function(p) local hitPlayer = game.Players:GetPlayerFromCharacter(p.Parent) local canDamage = hitPlayer.Team ~= LocalPlayer.Team if canDamage then p.Parent.Humanoid:TakeDamage(25) sound4:Play() script.Parent.CanDamage.Value = false end end) ItsRechintech -5 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local sound4 = script.Parent.Sound4
script.Parent.blade.Touched:connect(function(p)
    local hitPlayer = game.Players:GetPlayerFromCharacter(p.Parent)
    canDamage = hitPlayer.Team ~= LocalPlayer.Team
    if canDamage then
   p.Parent.Humanoid:TakeDamage(25)
    sound4:Play()
   script.Parent.CanDamage.Value = false
  end
end)

THIS IS NOT WORKING

0
Are there any errors, or does it just not work? NexanianStudios 91 — 6y
0
One error] ItsRechintech -5 — 6y

Answer this question