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.
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.