I am making a GUI that shows player’s teams they can join based on whether or not they’re in certain groups (they can be in more than one). Right now my script only shows one group because I’m using elseif. But you can’t use more than one if inside a function. So how would I show multiple at once?
Current Script (Only two groups ease of understanding)
local frame = game.StarterGui.TeamSelect:WaitForChild("Spots")
local spotcheck = game.ReplicatedStorage.SpotsTaken
game.Players.PlayerAdded:Connect(function(plr)
if plr:IsInGroup(7703529) then
spotcheck.A.Value = true
frame.SpotA.Visible = true
frame.SpotA.Text = "Department of External Affairs"
elseif plr:IsInGroup(7680944) then
if spotcheck.A.Value == false then
spotcheck.A.Value = true
frame.SpotA.Visible = true
frame.SpotA.Text = "Intelligence Agency"
elseif spotcheck.A.Value == true then
spotcheck.B.Value = true
frame.SpotB.Visible = true
frame.SpotB.Text = "Intelligence Agency"
end
end
end)
You can use more than one if inside a function. Just make sure you end it correctly. A return statement in an if block will prevent the rest of the function from running if it gets ran, but that doesn’t effect this.
local frame = game.StarterGui.TeamSelect:WaitForChild("Spots")
local spotcheck = game.ReplicatedStorage.SpotsTaken
game.Players.PlayerAdded:Connect(function(plr)
if plr:IsInGroup(7703529) then
spotcheck.A.Value = true
frame.SpotA.Visible = true
frame.SpotA.Text = "Department of External Affairs"
end
if plr:IsInGroup(7680944) then
if spotcheck.A.Value == false then
spotcheck.A.Value = true
frame.SpotA.Visible = true
frame.SpotA.Text = "Intelligence Agency"
end
if spotcheck.A.Value == true then
spotcheck.B.Value = true
frame.SpotB.Visible = true
frame.SpotB.Text = "Intelligence Agency"
end
end
end)
Like tlr said, just make sure to order the groups from lowest priority to highest. So the farther down the group is, it will overwrite any other group above so keep that in mind