Why won't my TextButton script work?

I want to make it so when the player clicks on the text button, the play button would disappear slowly and then the loading bar appears and once it has completely loaded then the visible GUI would disappear and a new one would appear.

When I attempt to test this in-game it doesn’t work. I even implemented for it to print a message to show if it has been pressed or not but it doesn’t print anything at all meaning that there must be an error.

I’ve tried to fix it and check for any errors but did not find any. Already looked for solutions and didn’t find any either.

5 Likes

So can someone help me out or no?

3 Likes

Could you show the gui hierarchy in the explorer?

2 Likes

Yeah here it is.

image

2 Likes
  1. Try using :WaitForChild() when declaring the variables, maybe the script is running before everything has been completely loaded.

  2. Try replacing PlayButton.MouseButton1Click with PlayButton.Activated.

4 Likes

I will try that now and let you know if it works.

2 Likes

It didn’t work, anything other ideas?

2 Likes

I don’t think .Visible works in a tween have you tested it alone to see if that’s what’s causing the problem?

1 Like

Well I’m not sure if the tweening works or not and I can’t tell because it’s supposed to print that the button has been pressed if it has bene pressed but it’s not even doing that so there is no way to tell.

2 Likes

Updated the script as well.

2 Likes

Please, please PLEASE refrain from sending screenshots of code. We
a) cannot see it clearly and need to zoom in
b) cannot copy-paste the code
c) cannot quote certain parts of the code
d) cannot manipulate parts of the code and send it back to you.
Instead, paste your code and surround it a line of three backticks above and below your code.

1 Like

I will send the code then.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local MainGUI = LocalPlayer.PlayerGui:WaitForChild("Main")
local CharacterSelectionGUI = LocalPlayer.PlayerGui:WaitForChild("CharacterSelection")
local MainFrame = MainGUI:WaitForChild("Background")
local PlayButton = MainFrame:WaitForChild("PlayButton")
local TweenModule = require(game.ReplicatedStorage.Tween)
local TweenService = game:GetService("TweenService")

PlayButton.Activated:Connect(function()
    print("The play button has been pressed.")
	for i,Button in pairs(LocalPlayer.PlayerGui.Main.Background:GetDescendants()) do
	if Button:IsA("TextButton") then
		if Button.Name ~= "PlayButton" then
			TweenModule:GetTweenObject(Button,TweenInfo.new(1.5,Enum.EasingStyle.Quad),{Visible = false}):QueuePlay()
			end
		end
	end
    wait(1.5)
	for i,Images in pairs(LocalPlayer.PlayerGui.Main.Background:GetDescendants()) do
		if Images:IsA("ImageLabel") then
			if Images.Name ~= "MainBar" or Images.Name ~= "BarHolder" or Images.Name ~= "Bar" then
				TweenModule:GetTweenObject(Images,TweenInfo.new(0.1,Enum.EasingStyle.Quad),{Visible = true}):QueuePlay()
			end
		end
	end
	for i,Text in pairs(LocalPlayer.PlayerGui.Main.Background.MainBar.BarHolder:GetDescendants()) do
		if Text:IsA("TextLabel") then
			if Text.Name ~= "Text" then
				TweenModule:GetTweenObject(Text,TweenInfo.new(0.1,Enum.EasingStyle.Quad),{Visible = true}):QueuePlay()
			end
		end
	end
	for i,BarImage in pairs(LocalPlayer.PlayerGui.Main.Background.MainBar.BarHolder:GetDescendants()) do
		if BarImage:IsA("ImageLabel") then
			if BarImage.Name ~= "Bar" then
				TweenModule:GetTweenObject(BarImage,TweenInfo.new(10,Enum.EasingStyle.Quad),{Size = 0, 490,0, 80}):QueuePlay()
			end
		end
	end
    wait(10)
	MainGUI.Enabled = false
	CharacterSelectionGUI.Enabled = true
end)
2 Likes

what happened to the indentation :weary: this looks even more demonic
here is the way easier to read version

local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
local MainGUI = LocalPlayer.PlayerGui:WaitForChild(“Main”)
local CharacterSelectionGUI = LocalPlayer.PlayerGui:WaitForChild(“CharacterSelection”)
local MainFrame = MainGUI:WaitForChild(“Background”)
local PlayButton = MainFrame:WaitForChild(“PlayButton”)
local TweenModule = require(game.ReplicatedStorage.Tween)
local TweenService = game:GetService(“TweenService”)

PlayButton.Activated:Connect(function()
	print(“The play button has been pressed.”)
	for i,Button in pairs(LocalPlayer.PlayerGui.Main.Background:GetDescendants()) do
		if Button:IsA(“TextButton”) then
			if Button.Name ~= “PlayButton” then
				TweenModule:GetTweenObject(Button,TweenInfo.new(1.5,Enum.EasingStyle.Quad),{Visible = false}):QueuePlay()
			end
		end
	end
	wait(1.5)
	for i,Images in pairs(LocalPlayer.PlayerGui.Main.Background:GetDescendants()) do
		if Images:IsA(“ImageLabel”) then
			if Images.Name ~= “MainBar” or Images.Name ~= “BarHolder” or Images.Name ~= “Bar” then
				TweenModule:GetTweenObject(Images,TweenInfo.new(0.1,Enum.EasingStyle.Quad),{Visible = true}):QueuePlay()
			end
		end
	end
	for i,Text in pairs(LocalPlayer.PlayerGui.Main.Background.MainBar.BarHolder:GetDescendants()) do
		if Text:IsA(“TextLabel”) then
			if Text.Name ~= “Text” then
				TweenModule:GetTweenObject(Text,TweenInfo.new(0.1,Enum.EasingStyle.Quad),{Visible = true}):QueuePlay()
			end
		end
	end
	for i,BarImage in pairs(LocalPlayer.PlayerGui.Main.Background.MainBar.BarHolder:GetDescendants()) do
		if BarImage:IsA(“ImageLabel”) then
			if BarImage.Name ~= “Bar” then
				TweenModule:GetTweenObject(BarImage,TweenInfo.new(10,Enum.EasingStyle.Quad),{Size = 0, 490,0, 80}):QueuePlay()
			end
		end
	end
	wait(10)
	MainGUI.Enabled = false
	CharacterSelectionGUI.Enabled = true
end)
2 Likes

I don’t know how to do whatever you did to that message.

1 Like

Put 3 backticks (the little ` sign in the top left of your keyboard) at the start and end of your code like this:
```

print("hello")

```

1 Like

Alright I’ll try it now, thanks for the help.

1 Like

Thanks I’ll keep that in mind.

1 Like

and this outputs absolutely nothing?

1 Like

Yeah It doesn’t output anything at all.

1 Like

It didn’t work, I don’t know what’s wrong with it.

1 Like