I’m getting an issue with my “switch team” buttons loop. Basically, it loops through each button and checks if the player is in the group for them to switch to that team. If not, the button deletes. If so, the button stays and gets a function that switches the players team when pressed using a remote event. I tested with a print statement and confirmed the remote event was not the issue.
The code: (thats giving me the issue)
for i,v in pairs (stuff.Teams:GetChildren()) do
if v:IsA("TextButton") then
--check if player is in group or not
if player:IsInGroup(v.TeamID.Value) then
if v.TeamID.Value == 8204505 and v.Name ~= "Chaos Insurgency" then
CheckRank(v, "Class D", 8204505, 1)
CheckRank(v, "Foundation Personnel", 8204505, 8)
else
print(slot, v.Name)
v.Position = stuff.Slots:FindFirstChild(slot).Position
slot = slot + 1
end
else
v:Destroy()
end
--if player clicks on button
v.MouseButton1Click:Connect(function()
if player.Team ~= game.Teams:FindFirstChild(v.Name) and player:IsInGroup(v.TeamID.Value) then
rep:FireServer(v.Name)
end
end)
end
end
If you want to see the full code, I can send it to you, but the only other code is just the CheckRank function and some values, which to my knowledge have no bugs.
Sorry, forgot to state the issue as I had to retype the post a few times as the forum was having trouble.
When I start the game and press buttons, nothing happens. I tried this with other buttons too, and nothing would print when I told it to. However I am inclined to believe that it is my script that could be causing problems because that is the only script that is dealing with the team selector UI. After sending this message though, I will try copying my code to a new UI and seeing how it works to double check if it is the UI I am using for some reason.
Localscript. I just tested a button outside of the screenGUI with a print statement, and it prints, however the buttons to switch teams doesn’t even print when clicked.
It could be that you’re executing the loop too early as well. Try adding a wait(5) statement or something which makes sure that the stuff.Teams has all of its children before you iterate it.
I’ve been testing and can’t figure out what exactly is causing the problem. However, changing stuff.Teams:GetChildren() to stuff:GetDescendants() managed to fix it on my side.
Edit: It’s because you have buttons on top of each other. Your frame named “slots” has buttons that are on top of your team buttons. Only one of them take the input and it is not the team buttons. After deleting the “slots” frame, your script should work without any changes. stuff.Teams:GetChildren() is the more valid way to do it.