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

Why doesn't this change the team or kill me?

Here is the script:

local sign = script.Parent
local plr = game.Players.PlayerAdded:connect(plr)
local ding = false

function onClick()
	ding = true
	plr.TeamColor = BrickColor.new("Really blue")
	wait(3)
	plr.Humanoid.Health = 0
	ding = false
end

sign.ClickDetector.MouseClick:connect(onClick)

also, how can I change it to make it check the number of people on the team before it assigns the person?

1 answer

✓ Accepted answer

Here, try this.

local sign = script.Parent
--You didn't need to connect to the new player, if you're using a click detector then the event will automatically get the player, just add plr in the parenthesis of onClick
local ding = false

function onClick(plr)
	ding = true
	local peopleonblue = 0
--As for the checking the number of people on the team you could do the following code;
	for _,v in pairs(game:service("Players"):children()) do --It says don't use children or service in new works but it still works the same way (I made a question about children and GetChildren, no one answered).
		if v.TeamColor == BrickColor.new("Really blue") then --If the teamcolor is really blue then...
			peopleonblue = peopleonblue + 1 --Then count him/her as being on blue team.
		end --End if statement.
	end --End the loop
	if peopleonblue <= 5 then --If there are less than 6 people on blue team, it will do what you want the script to do to them.
		--Do what you need
	end
	plr.TeamColor = BrickColor.new("Really blue")
	wait(3)
	plr.Humanoid.Health = 0
	ding = false
end

sign.ClickDetector.MouseClick:connect(onClick)

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