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

Kill all players and then change their team script?

Asked by 10 years ago

So I've been trying to get this to work all day. I am seething with rage right now. I am ready to launch my game, but cannot because of this. I need it to work once a brick is clicked. I made the part, put the click detector in it, and this is the bit of the script I already have:

function ClickTime(Plyr)
for i,v in pairs(Players:GetPlayers()) do
v.Character:BreakJoints()
end
end
script.Parent.ClickDetector.MouseClick:connect(ClickTime)

However, that didn't work, and It didn't change the teams(Because I still don't know how to do that). So then I tried this:

local detect = script.Parent.ClickDetector -- Assuming the script is within a part, and the part has a ClickDetector in it

function kill()
        for i, v in pairs(game.Players:getPlayers()) do
        v.Character:breakJoints()
end

detect.MouseClick:connect(kill)

And that didn't work either. If someone can help me make these scripts kill all, that would be great. And if you need to know the teams, they are: "Really red" "Bright blue" "Bright yellow" And I am trying to change the teams to yellow.

1 answer

Log in to vote
2
Answered by 10 years ago
function killandteamchange()
for i, player in pairs(game.Players:GetChildren()) do
player.Character.Humanoid.Health = 0
local numPlayers = 0

for i, v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("TeamColor") == BrickColor.new("Really Red") then
numPlayers = numPlayers + 1
elseif v:FindFirstChild("TeamColor") ~= BrickColor.new("Bright Blue") then
    numPlayers = numPlayers - 1
end
end

if numPlayers == 0 then

local player = game.Players:GetPlayers()

local pickedPl = math.random(1, #player)
pickedPl.TeamColor = BrickColor.new("Really Red")

end
end

script.Parent.ClickDetector.MouseClick:connect(killandteamchange)

GOD ITS LONG AND IT TOOK LONG.

0
Thank you! Tallestmidget7 95 — 10y
Ad

Answer this question