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

How do you make a gui where only one person can be on that team and no one else can join?

Warden = game.Teams.Warden
NumberAllowed = workspace.NumberAllowed

function checkSurvivorNumber(mouse)
	local count = 0
	local mouse_player = game.Players:GetMousefromCharacter(mouse.Parent)
	local players = game.Players:getChildren()
	for i = 1, #players do
		if players[i] ~= nil then
		if players[i].TeamColor == game.Teams.Warden.TeamColor then
				count = count + 1
			end
		end
	end
	if count >= NumberAllowed then 
		return 
	end
	mouse.Parent.TeamColor = game.Teams.Lobby.TeamColor
	

		script.Parent.MouseButton1Click:connect(checkSurvivorNumber)

Hello, I've been working on this script for an hour, but I have no answer. I was wondering if anyone can help me thoroughly. What I am trying to do is to make a GUI where if there is already one person on the team, then whoever clicks the GUI for that team can not get onto the team NumberAllowed is a IntValue of 1 because there can only be one person on that team.

2 comments

0

You cant make a gui thats makes one person on a team :/ You can make a script but you havent explained at what the gui does to sto, etc

0

Wait i think i see whats wrong

1 answer

✓ Accepted answer

You have several problems. Ninjo is right in saying that you aren't checking the IntValue's value, but you have some other problems as well. These are things that should have shown in your output, so make sure you include that in the future.

The MouseButton1Click event doesn't have any built in parameters, so you can't use mouse.

The GetMouseFromCharacter method doesn't exist, so you can't use it.

Your code isn't as efficient or readable as it could be.

Also make sure this is a LocalScript, since it's in a GUI.

local warden = game.Teams.Warden
local numberAllowed = workspace.NumberAllowed 
local plr = game.Players.LocalPlayer --get the player

function checkNumberOnTeam(team)
	local playersOnTeam = 0
	for index,player in pairs(game.Players:GetPlayers()) do --Loop through players
		if player.TeamColor == team.TeamColor then --If they're on the same team as the team argument,
			playersOnTeam = playersOnTeam + 1 --Add 1 to the variable
		end
	end
	return playersOnTeam --Return the number on the team
end

script.Parent.MouseButton1Click:connect(function()
	if checkNumberOnTeam(warden) < numberAllowed.Value then --If there's no one on the team
		plr.TeamColor = BrickColor.new(tostring(warden.TeamColor)) --Team them to warden
	end
end)

Please comment if you have any questions about any part of this code.

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