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

How would I prevent a team kill? (edit)

Asked by
Xl5Xl5 65
9 years ago

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

01function kill()
02if bug == nil then return end
03if bug:FindFirstChild("Torso") == nil then
04local vCharacter = Tool.Parent
05local newPlayer = game.Players:playerFromCharacter(vCharacter)
06local message = Instance.new("Message")
07message.Text = ""
08message.Parent = newPlayer
09wait(1)
10message.Parent = nil
11else
12bug.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?
13reset()
14end
15end

Below is the button that if clicked on then the function will happen.

1local button5 = Instance.new("TextButton")
2button5.Name = "Button"
3button5.Text = "Kill"
4button5.BackgroundColor3 = Color3.new(0.752941, 0.752941, 0.752941)
5button5.Size = UDim2.new(0,70,0,25)
6button5.Position = UDim2.new(0,80,0,35)
7button5.Parent = frame
8button5.MouseButton1Click:connect(function() kill() end) -- When the kill function begins

1 answer

Log in to vote
1
Answered by 9 years ago

Simple. Store the player you want to kill in a value, and the current player in a value. Then, perform a check to see if they are on the same team. If they are not, then kill the target player.

Example:

01--This is a simple team only door that is in a localscript for easy access to the local player
02local Player = game.Players.LocalPlayer
03local Part = game.Workspace:WaitForChild('Door')
04 
05Part.Touched:connect(function(hit)
06    --Perform a check to see if hit is a player
07    if hit and hit.Parent:FindFirstChild('Humanoid') and game.Players:GetPlayerFromCharacter(hit.Parent) then
08        local target = game.Players:GetPlayerFromCharacter(hit.Parent)
09        --Make sure it is not the local player
10        if target ~= Player then
11            --Check to see what team they are on
12            if target.TeamColor ~= Player.TeamColor then
13                target.Character:BreakJoints()
14            else
15                print('Target is on the Players team')
16            end
17        end
18    end
19end)
0
How would I implement that into my kill function? Xl5Xl5 65 — 9y
0
I'm not exactly sure what your kill function is attempting to do. If you can explain it better I might be able to help. LordSpectrus 25 — 9y
0
the kill function kills the player when the gui button is clicked, then "if bug" area just check if the other player that has been hit has been "infected" then it carries out a message then carries out the other players death Xl5Xl5 65 — 9y
Ad

Answer this question