I am trying to make this script get all the player's, clone a ImageButton named Template, Change a TextLabel's text to their name, then name the ImageButton to the Player's name, and so far it work's beside's it not destroying all the ImageButton's, can anyone tell me why?

function GetPlayers()
	for _,g in pairs(script.Parent:GetChildren()) do
		if g.className == "ImageButton" then
			g:Destroy()
		end
		for i,v in pairs(game.Players:GetPlayers()) do
			local temp = script.Template:Clone()
			temp.Parent = script.Parent
			temp.Name = v.Name	
			temp.Header.Text = v.Name
			temp.Position = UDim2.new(0,0,0,17*i)
			temp.Visible = true		
		end
	end	
end

while wait(3) do
	GetPlayers()
end

1 comment

0

Try if g:IsA("ImageButton") then