hi guys so it works and clones the buttons but the new cloned buttons dont work when new player joins
if i put it in a while wait loop it works but not good the buttons dont respond until 3 or 4 clicks. all help is greatly appreciated. thank you
game.Players.PlayerAdded:Connect(function(player)
local clone = TextButton:Clone()
clone.Visible = true
clone.Name = player.Name
end)
--[[ so when i joins it shows me buttons with all players names.
when new player joins it clones that players button to me
but the new MouseButton1Click:Connect doesnt work]]
for i,v2 in pairs(buttons:GetChildren()) do --{problem here. registers all exicting buttons but not the new buttons after script is executed }
if v2:IsA("TextButton") then
v2.MouseButton1Click:Connect(function()
if v2.TextColor3 == Color3.fromRGB(255, 255, 255) then
v2.TextColor3 = Color3.fromRGB(255, 0, 0)
else v2.TextColor3 = Color3.fromRGB(255, 255, 255)
end
end )
end
end
local actParent = script.Parent -- put your parent here
game.Players.PlayerAdded:Connect(function(player)
local clone = TextButton:Clone()
clone.Visible = true
clone.Name = player.Name
clone.Parent = actParent
end)
local registredButtons = {}
function Update(buttons)
for i,v2 in pairs(buttons:GetChildren()) do
if v2:IsA("TextButton") then
if not(table.find(registredButtons, v2)) then
table.insert(registredButtons, v2)
v2.MouseButton1Click:Connect(function()
if v2.TextColor3 == Color3.fromRGB(255, 255, 255) then
v2.TextColor3 = Color3.fromRGB(255, 0, 0)
else
v2.TextColor3 = Color3.fromRGB(255, 255, 255)
end
end)
end
end
end
end
while wait() do
Update(actParent)
end