the kill function kills the player when the gui button is clicked, then "if bug" area just checks if the other player that has been hit has been "infected" then it carries out a message then carries out the other player that has been infected death
These two chunks here are relevant to a Players death. The first chunk is the function and the second chunk is the GUI, This all works fine, but I want it able to not kill a Player if the Player is on the same team.
I hope I made sense! Please help
function kill()
if bug == nil then return end
if bug:FindFirstChild("Torso") == nil then
local vCharacter = Tool.Parent
local newPlayer = game.Players:playerFromCharacter(vCharacter)
local message = Instance.new("Message")
message.Text = ""
message.Parent = newPlayer
wait(1)
message.Parent = nil
else
bug.Humanoid.Health = 0 -- This is where it kills player regardless of which team, or even if its an NPC how can I make it so it doesn't kill the people on the same team?
reset()
end
end
Below is the button that if clicked on then the function will happen.
local button5 = Instance.new("TextButton")
button5.Name = "Button"
button5.Text = "Kill"
button5.BackgroundColor3 = Color3.new(0.752941, 0.752941, 0.752941)
button5.Size = UDim2.new(0,70,0,25)
button5.Position = UDim2.new(0,80,0,35)
button5.Parent = frame
button5.MouseButton1Click:connect(function() kill() end) -- When the kill function begins

5 comments
I have tried that, but it fails to work, i changed it around too function kill() if bug == nil then return end if bug:FindFirstChild("Torso") == nil then local vCharacter = Tool.Parent local newPlayer = game.Players:playerFromCharacter(vCharacter) local message = Instance.new("Message") if bug then if newPlayer.TeamColor == bug.TeamColor then return end --Do stuff here else if bug:Find
Here is a link to full script http://pastebin.com/Pdmh8Q8x
You need to add a BrickColor value to the NPC called "TeamColor" without the quotes.
Still dont work, I put in a BrickColor value inside an NPC renamed the Value TeamColor also made sure the team color underneath is not the same as the team I am in
Follow the code example carefully. I check to see if the bug is connected to a player and then run one code block and if it's not, I run another code block.