Team Name to a Text Label Text Change

Hello, I’ve been struggling at this for a bit now. I am trying to (when the Bindable function gets fired from clicking a button, it changes the players team and if there isn’t any room in said team it shows the player “Team is Full!” and the team name after a wait() period.

The code thats hyphened is ones I tried but didn’t work.

The teamToSelect is the team name after the player selects what team they want to be on.
I just want to change a text label to say the team is full and try a different team.

How do I search in the parameters of player.PlayerGui.TeamSelect.Frame for a team name that the button matches that the player chose?

    game:GetService("ReplicatedStorage").Events.SelectTeam.OnServerEvent:Connect(function(player,t 
    eamname)

    local teamToSelect = game.Teams:FindFirstChild(teamname)

    local teamcount = teamToSelect:GetPlayers()

    local teamlimit = #teamcount

   local teamIDtoFind = teamToSelect.Name

 --local teamIDs = {"Crypto-Currency Tycoon","Player Points Business Tycoon","Robux Business 
 Tycoon","Tix Business Tycoon"}

 --local teamIDs = {

-- teamone = "Crypto-Currency Tycoon" ,

-- teamtwo = "Player Points Business Tycoon" ,

-- teamthree = "Robux Business Tycoon",

-- teamfour = "Tix Business Tycoon",

-- }

 --local function findTeam(whichTeam, teamIDtoFind)

-- for team, value in pairs(whichTeam) do

-- if value == teamIDtoFind then

-- return teamNum

-- end

-- end

-- end


     local team = findTeam(teamIDtoFind)

      -- local function getSelectedTeam(teamName)

      -- for SelectedTeam, team in pairs(teamIDs) do

       -- if team == teamName then

          -- return SelectedTeam

        -- end

   -- end

 -- end

 -- local SelectedTeam = getSelectedTeam(teamIDtoFind)

  if teamToSelect and teamlimit == 0 then
 player.Team = teamToSelect
 player.Character.Humanoid.Health = 0
  player.PlayerGui.TeamSelect:FindFirstChild("Frame"):Destroy()
   warn("perhaps it will stop buggin ")
    return true
    else
     player.PlayerGui.TeamSelect.Frame:FindFirstChild(teamToSelect.TextLabel.Text == "Team is 
   full!")
         wait(1)
      player.PlayerGui.TeamSelect.Frame:FindFirstChild(teamToSelect.TextLabel.Text == 
       teamToSelect

     warn(player.Name..", "..teamToSelect.Name.." is full!")
 return false
 end
end)


)

my eyes…
the problem is in here.

  1. Why in the world you typed here double = ?
  2. Search how to use FindFirstChild(), because it should look like that:
local teamSelect = player.PlayerGui:FindFirstChild("TeamSelect")
if teamSelect ~= nil then
      local textLabel = teamSelect.Frame.TextLabel
      textLabel.Text = "Team is full!"

      task.wait(1)
      if textLabel ~= nil then
         textLabel.Text = teamToSelect.Name
      end
end

Is there a way to search and select for the image button name that matches the team that the player selected? The textLabel is a child of the image button
Roblox dev forum 2

Frame:FindFirstChild(tostring(player.TeamColor).." tButton") -- there two dots
if like that, button should be named “Really Red tButton”, etc.
i just gived a hint, now try to implement it by yourself.

still having problems I’ve tried it multiple ways and it still wont change the text. It gives me trouble when trying to change the TextLabel.

I dont understand why its saying TextLabel is Nil.

if teamToSelect and teamlimit == 1 then
	player.Team = teamToSelect
	player.Character.Humanoid.Health = 0
	player.PlayerGui.TeamSelect:FindFirstChild("Frame"):Destroy()
return true 
else 
	local teamSelect = player.PlayerGui:FindFirstChild("TeamSelect")
	if teamSelect ~= nil then
		local textLabel = teamSelect.Frame:FindFirstChild(tostring(player.Team.Name).." Button")
		textLabel.TextLabel.Text = "Team is full!"

		task.wait(1)
		if textLabel ~= nil then
			textLabel.TextLabel.Text = teamToSelect.Name
		end
	end
return false 
end
end)

    local teamSelect = player.PlayerGui:FindFirstChild("TeamSelect")
	if teamSelect ~= nil then
		local textLabel = teamSelect.Frame:FindFirstChild(tostring(player.Team.Name).." Button")
		local textLabelF = textLabel:FindFirstChildWhichIsA("TextLabel")
		textLabelF.Text = "Team is full!"
		task.wait(1)
		if textLabel ~= nil then
			textLabelF.Text = teamToSelect.Name

got another error this way

try printing out tostring(player.Team.Name).." Button". What do you notice? Is this the name of the textlabel (or textbutton…?)

is your label named exactly “Red Team Button” ? – or so, but the spaces.

There are a couple of issues in your code that are preventing it from working correctly. Here are the changes you can make to fix the issues:

  1. The parameter for the event callback function is “teamname”, but you are using “teamName” in your code. Make sure the parameter name matches the case correctly.
  2. You can use the “Text” property of the button to match it with the team name instead of finding it in the parameters of the playerGui. You can do this by looping through the buttons and checking if their Text property matches the team name.
  3. The code for showing the message “Team is Full!” is incorrect. You can create a TextLabel in the Frame and show it when the team is full.

Here’s the modified code:

game:GetService("ReplicatedStorage").Events.SelectTeam.OnServerEvent:Connect(function(player, teamname)

    local teamToSelect = game.Teams:FindFirstChild(teamname)
    local teamcount = teamToSelect and teamToSelect:GetPlayers() or {}

    local teamlimit = 2 -- set the team limit here

    if #teamcount < teamlimit then
        player.Team = teamToSelect
        player.Character.Humanoid.Health = 0
        player.PlayerGui.TeamSelect:FindFirstChild("Frame"):Destroy()
        warn("perhaps it will stop buggin ")
        return true
    else
        local frame = player.PlayerGui.TeamSelect.Frame
        local teamFullLabel = frame:FindFirstChild("TeamFull")
        if not teamFullLabel then
            teamFullLabel = Instance.new("TextLabel")
            teamFullLabel.Name = "TeamFull"
            teamFullLabel.Size = UDim2.new(1, 0, 0, 20)
            teamFullLabel.Position = UDim2.new(0, 0, 0.8, 0)
            teamFullLabel.BackgroundTransparency = 1
            teamFullLabel.Text = "Team is full!"
            teamFullLabel.Parent = frame
        end
        for _, button in ipairs(frame:GetChildren()) do
            if button:IsA("TextButton") and button.Text == teamname then
                button.Visible = false
                break
            end
        end
        wait(1)
        teamFullLabel.Visible = false
        return false
    end
end)

You can change the “teamlimit” variable to set the maximum number of players allowed in a team. This code creates a TextLabel with the text “Team is full!” when the team is full and hides the button for that team. After a delay of 1 second, the label is hidden again.

I hope this helps you!

1 Like

it prints out nil in the output

yes its exactly how it should be.

This works great! Should’ve done something like this at the beginning. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.