Button won't spawn

Whenever a player joins, I want buttons to spawn if the player is in a particular group with a specific rank that can put them on a team.

The buttons won’t spawn. I got values set in a table.

Module Script

local teams = {
– {TEAM-NAME,TEAM-COLOR,GROUP-ID,TOOLS,GUI’s}
{“Citizen”,“Medium red”,5387760,{},{}}

}

local specialteams = {
– {TEAM-NAME,TEAM-COLOR,GROUP-ID,GROUP-RANK,TOOLS,GUI’s}
{“President”,“Medium red”,5387760, 20,{},{}}

}

local developers = {“NotABrad”,“JxcobMattis”}

–[[
DO NOT EDIT BELOW THIS POINT.
–]]

local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local teamEvent = game.ReplicatedStorage.ApplyTeam
local Id = 5387760

if player:GetRoleInGroup(teams[3]) > 1 then
local teambtn = Instance.new(“TextButton”)
local team = Instance.new(“Team”)
– TEAM BTN
teambtn.Text = teams[1]
teambtn.BackgroundTransparency = “0.7”
teambtn.Size = UDim2.new(0, 72, 0, 18)
teambtn.Font = “SourceSansBold”
teambtn.TextColor3 = Color3.new(255, 255, 255)
teambtn.TextScaled = true
teambtn.Parent = player.PlayerGui.StartGui.Teams
teambtn.BackgroundColor3 = Color3.new((math.random()), (math.random()),( math.random()))

teambtn.MouseButton1Click:Connect(function()
	team.Name = teams[1]
	team.TeamColor = BrickColor.new("Storm blue")
	player.plrStats.TeamId = teams[3]
	teamEvent:FireServer(team.Name, team.TeamColor, Id)
	end)

end

return teams

Script

local DataStoreService = game:GetService(“DataStoreService”)
local plrDataStore = DataStoreService:GetDataStore(“plrDataStore”)
local nickEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“ApplyNick”)
local Players = game:GetService(“Players”)
local billboardgui = game:GetService(“ServerStorage”):WaitForChild(“RankGui”)

game.Players.PlayerAdded:Connect(function(player)
local plrStats = Instance.new(“Folder”)
plrStats.Name = “plrStats”
plrStats.Parent = player

local rpName = Instance.new("StringValue")
rpName.Name = "rpName"
rpName.Parent = plrStats

local teamId = Instance.new("StringValue")
teamId.Name = "TeamId"
teamId.Parent = plrStats



local playerID = player.UserId.."#user"

local data
local success, errormessage = pcall(function()
	data = plrDataStore:GetAsync(playerID)
end)

if success then
	rpName.Value = data
	player.CharacterAdded:Connect(function(char)
	local clonedgui = billboardgui:Clone()
	clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	clonedgui.Frame.NICKNAME.Text = player.plrStats.rpName.Value .. " - " .. player.UserId
	if player.plrStats.TeamId.Value == "0" then
		clonedgui.Frame.RANK.Text = "Visitor"
	else
		clonedgui.Frame.RANK.Text = player:GetRoleInGroup(player.plrStats.TeamId.Value) 
	end

	end)
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local playerID = player.UserId…“#user

local data = player.plrStats.rpName.Value

local success, errormessage = pcall(function()
	plrDataStore:SetAsync(playerID, data)
end)
if success then
	print(player.UserId.."'s Data saved!")
else
	print("Error saving"..player.UserId.."'s Data")
	warn(errormessage)
end

end)

nickEvent.OnServerEvent:Connect(function(plr,text)
local filteredNick = game:GetService(“Chat”):FilterStringForBroadcast(text,plr)
local alert = plr.PlayerGui.Menu.Alert
plr.plrStats.rpName.Value = filteredNick

end)

game.Players.PlayerRemoving:Connect(function(player)

end)

Any help will be appreciated!

On this line here you’re referencing teams[3]. At least in the module script there is only 1 index in the teams table.

local teams = {
– {TEAM-NAME,TEAM-COLOR,GROUP-ID,TOOLS,GUI’s}
{“Citizen”,“Medium red”,5387760,{},{}}

}

It looks like the first line I mentioned should be
if player:GetRoleInGroup(teams[1][3]) > 1 then

This should get the id 5387760

I’m not sure that’s the only issue here, but it’s at least one of them so we can go from here.

There are supposed to be multiple lines such as
– {TEAM-NAME,TEAM-COLOR,GROUP-ID,TOOLS,GUI’s}
{“Citizen”,“Medium red”,5387760,{},{}}
{“FBI”,“Medium red”,5511008,{},{}}

I want the script to go through all the lines and they would create buttons for every group-id that they’re in.

But that still doesn’t make much sense with the way that line is. You would be passing a table into GetRoleInGroup.

How would I make it go through all the tables and check the third column for group ids?

You would want to use a for loop. Like

for _, team in pairs(teams) do
  if player:GetRoleInGroup(team[3]) > 1 then
    ...
  end
end

New Script

Script

local teams = {
– {TEAM-NAME,TEAM-COLOR,GROUP-ID,TOOLS,GUI’s}
{“Citizen”,“Medium red”,5387760,{},{}}

}

local specialteams = {
– {TEAM-NAME,TEAM-COLOR,GROUP-ID,GROUP-RANK,TOOLS,GUI’s}
{“President”,“Medium red”,5387760, 20,{},{}}

}

local developers = {“NotABrad”,“JxcobMattis”}

–[[
DO NOT EDIT BELOW THIS POINT.
–]]

local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local teamEvent = game.ReplicatedStorage.ApplyTeam
local Id = 5387760

for _, team in pairs(teams) do
if player:GetRoleInGroup(team[3]) > 1 then
local teambtn = Instance.new(“TextButton”)
local team = Instance.new(“Team”)
– TEAM BTN
teambtn.Text = team[1]
teambtn.BackgroundTransparency = “0.7”
teambtn.Size = UDim2.new(0, 72, 0, 18)
teambtn.Font = “SourceSansBold”
teambtn.TextColor3 = Color3.new(255, 255, 255)
teambtn.TextScaled = true
teambtn.Parent = player.PlayerGui.StartGui.Teams
teambtn.BackgroundColor3 = Color3.new((math.random()), (math.random()),( math.random()))

teambtn.MouseButton1Click:Connect(function()
	team.Name = teams[1]
	team.TeamColor = BrickColor.new("Storm blue")
	Id = team[3]
	teamEvent:FireServer(team.Name, team.TeamColor, Id)
	end)

end
end

return teams

return teams

No buttons are being made? Does it not work in Studio?