Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make the textButton appear ?

Asked by 3 years ago

I want to make a button that when clicked, will get a list of all players. The only problem to this is that the button is invisible/transparent but in the code, I made all transparency values to 0 and visible to true

local kick = script.Parent

local function Choose()
    local players = game.Players:GetPlayers()
    for i = 1,#players do
        local newgui = Instance.new("TextButton")
        newgui.Name = "newgui"
        newgui.Parent = game.StarterGui.ScreenGui
        newgui.BackgroundTransparency = 0
        newgui.Visible = true
        newgui.ZIndex = 1
        newgui.Position = UDim2.new(0.5, 0,0, 0)
        newgui.Size = UDim2.new(0, 200,0, 50)
        newgui.Text = tostring(players[i])
    end
end

kick.MouseButton1Click:Connect(Choose)

I can see it is on the screen by selecting it in the explorer but it is just invisible. The text value is equal to denbra37 but it is transparent too.

0
I don't if this will help, but maybe try creating a frame that will hold all your text buttons, then set the frame visible? Also, is the 'ScreenGui' already existing? Maybe you need to define it beforehand. Padugz 40 — 3y
0
uhhh maybe try at the end visible = false? topsporter2007 -4 — 3y
0
screenGui is already existing denbra37 34 — 3y
0
I've parented it to a frame but it doesn't work too even if frame.ten denbra37 34 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

First of all, you can't use StarterGui, because it immediately replicates to the PlayerGui. That's why it doesn't work. You need to set the parent to the PlayerGui and not the StarterGui.

local kick = script.Parent

local function Choose()
    local players game.Players:GetPlayers()
    for i, v in pairs(players) do --I suggest using an in pairs loops instead, as it is more efficient.
        local gui = Instance.new("TextButton")
        gui.Name = "newgui"
        gui.Parent = v.PlayerGui
        gui.BackgroundTransparency = 0
        gui.Visible = true
        gui.ZIndex = 1
        gui.Position = UDim2.new(0.5,0,0,0)
        gui.Size = UDim2.new(0,200,0,50)
        gui.Text = tostring(players[i])
    end
end

kick.MouseButton1Click:Connect(Choose)
0
There was a bit of error but I corrected them of my own, thx ! denbra37 34 — 3y
Ad

Answer this question