Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TextButton not working when clicked, Why?

I am trying to make a text button when pressed print "working" to the console, but the button when pressed does nothing (in studio) and in a game the GUI does not even appear...

The script has been tried in StarterPack and StarterGui..

Making Gui:

--ScreenGui
local Screen = Instance.new("ScreenGui")
Screen.Parent =  game.StarterGui
--Frame
local Frame = Instance.new("Frame")
Frame.Parent = Screen
Frame.Size = UDim2.new(1,0,1,0)
Frame.BackgroundTransparency = 0.5
--Back
local Back = Instance.new("TextButton")
Back.Parent = Frame
Back.Name = "back"
Back.Text = "Back"
Back.Position = UDim2.new(0,0,0.1,0)
Back.Size = UDim2.new(0,50,0,50)

Functions (same script):

function onClick()
	print ("working")
end

Back.MouseButton1Click:connect(onClick)

1 answer

✓ Accepted answer

The problem is right here

local Screen = Instance.new("ScreenGui")
Screen.Parent =  game.StarterGui

That whole Gui is only going in StarterGui. That means that when you bind the input at

function onClick()
    print ("working")
end

Back.MouseButton1Click:connect(onClick)

you're only binding the input for the Gui in the StarterGui. Perhaps try adding it straight to the Player:

game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(c)
--ScreenGui
local Screen = Instance.new("ScreenGui")
Screen.Parent =  p.PlayerGui
--Frame
local Frame = Instance.new("Frame")
Frame.Parent = Screen
Frame.Size = UDim2.new(1,0,1,0)
Frame.BackgroundTransparency = 0.5
--Back
local Back = Instance.new("TextButton")
Back.Parent = Frame
Back.Name = "back"
Back.Text = "Back"
Back.Position = UDim2.new(0,0,0.1,0)
Back.Size = UDim2.new(0,50,0,50)
Back.MouseButton1Click:connect(function()
    print ("working")
end)
end)
end)

That'll create the Gui inside of the Player every time they spawn.

This discussion is preserved as it was. New answers, comments, and votes are closed.