Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I PREVENT Team Killing?

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

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

11 comments

0

Not sure if I'm doing this right, but I put this I think where you said to

0

But it did not work

0

In between line 2 and 3 of second script

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?

0

Whoops, change “canAttack” to “canDamage”

0

Also, did you make localplayer a variable that has the local player in it?

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

0

I'll post the new one that's still not working below.

0

Since its a tool, at the beginning, set the player to script.Parent.Parent

0

My script isn't functioning, could you edit your post and just post the fixed one for me? If so thanks :)

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)

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

2 comments

0

Are there any errors, or does it just not work?

0

One error]

This discussion is preserved as it was. New answers, comments, and votes are closed.