Admin Panel Error Help

So I have an Admin Panel, where there is a list of player and if we click, we choose that person and in this Admin Panel we can write using text box to change that player team, how can make that happen? This is my latest Script

Server Script

game.ReplicatedStorage.AdminEvent.OnServerEvent:Connect(function(plr,action,arg1,arg2)
	local Teams = game:GetService("Teams")
	local iswhitelisted =whitelist:CheckWhitelist(plr.Name)
	if iswhitelisted == false then 
		return 
	end
	if action == "teamchanger" then
		arg1.TeamColor = Teams[arg2].TeamColor
		arg1:LoadCharacter()
	end
end)

Local Script

local rs = game:GetService("ReplicatedStorage")
local remote = rs:FindFirstChild("AdminEvent")
local whitelist = require(rs.Whitelist)
local plr = game.Players.LocalPlayer
local chosenplr = plr
-- Player List 
local iswhitelisted = whitelist:CheckWhitelist(game.Players.LocalPlayer.Name)
if iswhitelisted == false then  rs.Whitelist:Destroy() script.Parent.Panel:Destroy() script:Destroy() return end

function fixcanvas()
	local amount = script.Parent.Panel.playerList:GetChildren() 
	local fixedamount = #amount-1
	print(fixedamount)	script.Parent.Panel.PlayerList.CanvasSize = UDim2.new(0,0,0,fixedamount*35)
end


for i,v in pairs(game.Players:GetPlayers()) do
	local username = script.Username:Clone()
	username.Name = v.Name
	username.Text = v.Name
	username.Parent = script.Parent.Panel.playerList
	fixcanvas()
	username.MouseButton1Click:Connect(function()
		if game.Players:FindFirstChild(username.Name) then
			chosenplr =  game.Players:FindFirstChild(username.Name)
		end
	end)
end
game.Players.PlayerAdded:Connect(function(plr)
	local username = script.Username:Clone()
	username.Name = plr.Name
	username.Text = plr.Name
	username.Parent = script.Parent.Panel.playerList
		fixcanvas()
username.MouseButton1Click:Connect(function()
		if game.Players:FindFirstChild(username.Name) then
			chosenplr =  game.Players:FindFirstChild(username.Name)
                        print(chosenplr)
		end
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	local name = script.Parent.Panel.playerList:FindFirstChild(plr.Name)
	if name then
		name:Destroy()
	end
		fixcanvas()

end)


for i,buttons in pairs(script.Parent.Panel.ClientSided.Buttons:GetChildren()) do
	buttons.MouseButton1Click:Connect(function()
	local arg2 = nil
	if buttons:FindFirstChildOfClass("TextBox") then
		arg2 = buttons:FindFirstChildOfClass("TextBox").Text
	end
	print(arg2)
	remote:FireServer(buttons.Name,chosenplr,arg2)
	end)
end

The GUI, Whitelist, PlayerList all works, but when I click the player on the playerList(Text Button) doesn’t print anything and doesn’t make it chosenplr even though I make it print(chosenplr), and I want to make them team change but with the team name based on input text box. Please I need solution, if you see any error on this that make the script doesn’t work, please help me, because in studio output doesn’t show any error.

1 Like

Please, I need solution for this…

Are you sure the button is called “teamchanger”? From what I can tell, you’re providing “buttons.Name” as the “action” argument.

Yes, Sir. So do you know what’s wrong?

I have already answered this. Stop making so many posts about the same thing (classed as spam in the rules).

Loop like what then? I don’t really understand.

Well how your code currently works is it runs through the code (so basically it runs through the code from top to bottom). It will go through the buttons but due to it only doing it once the for i, buttons in pairs loop will loop once when the script runs but then will not do it again.

So what should i do? while true do I suppose?

Well that is one way but another way is to have a local script in each of the buttons with that code in so that when it is clicked.

I don’t really suggest doing while true loops as they can lag the hell out of games if used loads.