. Advertisement .
..3..
. Advertisement .
..4..
Recently, I ran some of my programs code, and it gave the warning text:
Connect is not a valid member of TextButton "Players.Artemka_KRYT.PlayerGui.PrisonByGhosty.MenuButton.BackGround.Taravatar.TargBox.PlayersList.Artemka_KRYT"
While searching, I realized that some people added some command lines in my sample above. But I don’t think it is the best way to correct the problem – Connect is not a valid member of TextButton How would you explain this trouble? or Is there a better way? Below is the detail of the command that I used:
for i, v in pairs(game.Players:GetChildren()) do ---gets players in list [PlayersList is a ScrollingFrame] when i join game
thc = i/25
local Player = Instance.new("TextButton")
Player.Name = v.Name
Player.Parent = PlayersList
Player.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Player.BackgroundTransparency = 0.800
Player.Position = UDim2.new(-0.00711364765, 0, thc, 0)
Player.Size = UDim2.new(0, 100, 0, 30)
Player.Font = Enum.Font.FredokaOne
Player.Text = v.Name
Player.TextColor3 = Color3.fromRGB(255, 255, 255)
Player.TextScaled = true
Player.TextSize = 14.000
Player.TextWrapped = true
end
local plr = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(jplr) ---Adds new player in list
print(jplr, 'joined')
for a, b in pairs(PlayersList:GetChildren()) do
b:Destroy()
end
for i, v in pairs(game.Players:GetChildren()) do
thc = i/25
local Player = Instance.new("TextButton")
Player.Name = v.Name
Player.Parent = PlayersList
Player.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Player.BackgroundTransparency = 0.800
Player.Position = UDim2.new(-0.00711364765, 0, thc, 0)
Player.Size = UDim2.new(0, 100, 0, 30)
Player.Font = Enum.Font.FredokaOne
Player.Text = v.Name
Player.TextColor3 = Color3.fromRGB(255, 255, 255)
Player.TextScaled = true
Player.TextSize = 14.000
Player.TextWrapped = true
end
end)
game.Players.PlayerRemoving:Connect(function(lplr) ---Remove's Players which leave the game
print(lplr, 'left')
for a, b in pairs(PlayersList:GetChildren()) do
b:Destroy()
end
for i, v in pairs(game.Players:GetChildren()) do
if v.Name ~= lplr.Name then
thc = i/25
local Player = Instance.new("TextButton")
Player.Name = v.Name
Player.Parent = PlayersList
Player.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Player.BackgroundTransparency = 0.800
Player.Position = UDim2.new(-0.00711364765, 0, thc, 0)
Player.Size = UDim2.new(0, 100, 0, 30)
Player.Font = Enum.Font.FredokaOne
Player.Text = v.Name
Player.TextColor3 = Color3.fromRGB(255, 255, 255)
Player.TextScaled = true
Player.TextSize = 14.000
Player.TextWrapped = true
end
end
end)
for g, n in pairs(PlayersList:GetChildren()) do
local ind = n.Text
PlayersList[n.Text]:Connect(function()
TargBox.Text = n.Name
end)
end
The cause: This error happens because you have to connect to an event on the TextButton, not the button itself.
Solution: I suggest the Activated event as it fires when someone clicks on the button, and it also works on mobile.