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

Anti-Team kill script in Weapons?

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

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)

4 comments

0

Did it work?

0

I guess It works

0

I dunno, haven't used the script yet

0

Those variables would not work with my script i think

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