[SOLVED] Problems with MouseButton1Click

I am making an application system for my game. Everything works properly, but when I click the NextButton, nothing happens and things don’t print.

Explorer
Capture

Code (This is the first ever application system I’m working on. Sorry if code is sloppy.)

local PlayerGui = game.Players.LocalPlayer.PlayerGui
local TransparentLayer = PlayerGui:WaitForChild("Application")["Base"]["Transparent Layer"]
local IntroductionTemplate = TransparentLayer["Introduction Template"]
local ReadyButton = IntroductionTemplate:FindFirstChild("ReadyButton")
local NextButton = TransparentLayer["Question Template"]["NextButton"]

IntroductionTemplate.Visible = true

local SavedAnswers = {}

local TimeLimit = 300
local NotedTimeLimit = 300

local Functions = {}
local Trello = {}

function Functions:BaseFunction(QuestionNum, Question)
	local QuestionString = "Q"..QuestionNum..". "..Question
	local QuestionTemplate = TransparentLayer["Question Template"]

	if IntroductionTemplate then
		local HidingPos = UDim2.new(2,0,0,0)
		local TargetPos = UDim2.new(0.012,0,0,0)
		IntroductionTemplate:TweenPosition(HidingPos, "Out", "Quint", 1)
		repeat wait() until IntroductionTemplate.Position == HidingPos
		IntroductionTemplate:Destroy()
		
		local QuestionBox = QuestionTemplate.QuestionBox
		QuestionBox.Text = QuestionString
		
		QuestionTemplate.Visible = true
		QuestionTemplate:TweenPosition(TargetPos, "Out", "Quint", 1)
	end
	
	if TransparentLayer:FindFirstChild("Question Template") then
		local Question = TransparentLayer:FindFirstChild("Question Template")
		local HidingPos = UDim2.new(2,0,0,0)
		local TargetPos = UDim2.new(0.012,0,0,0)
		Question:TweenPosition(HidingPos, "Out", "Quint", 1)
		repeat wait() until Question.Position == HidingPos
		
		local QuestionBox = Question.QuestionBox
		QuestionBox.Text = QuestionString
		
		Question.Visible = true
		Question:TweenPosition(TargetPos, "Out", "Quint", 1)
	end
end

function OnNBClick()
	print("got to the clicked function") -- Not printing
	local Times = 0
	if Times == 0 then
		Times = Times + 1
		Functions:BaseFunction("2", "Why do you choose to work at Reiné over other companies?")
	elseif Times == 1 then
		Times = Times + 1
		Functions:BaseFunction("3", "Why do you feel like you should be accepted over other applicants & what special abilities do you possess?")
	elseif Times == 2 then
		Times = Times + 1
		Functions:BaseFunction("4", 'Correct this sentence: Hay welcome to rénay cafwe. Im gladd too be takinq youre ordier todeay howw may i helpp!')
	end
end

function Trello:sendResults()
	
end

if TransparentLayer:FindFirstChild("Introduction Template") then
	local IntroductionTemplate = TransparentLayer:FindFirstChild("Introduction Template")
	local ReadyButton = IntroductionTemplate:FindFirstChild("ReadyButton")
	ReadyButton.MouseButton1Click:Connect(function()
		Functions:BaseFunction("1", "If you were to greet a customer at the cafe, what would be your greeting?")
	end)
end

NextButton.MouseButton1Click:Connect(OnNBClick) -- Supposed to connect.

Gif
https://gyazo.com/a5e7f4c112391c0b680ca287e220cfde

Is this a simple mistake?

2 Likes

Still doesn’t work. I don’t think that is the issue.

1 Like

Okay lemme just review the code for a bit

1 Like

That’s not a mistake, I use the Click function as well and it works fine. There’s probably something else going on.

@Aerosphia, add some print statements in your BaseFunction. I think there is something holding up in there.

2 Likes

I have a lot of variables and things that aren’t even put into the code yet. Sorry about that.

1 Like

Try using a local function instead of just a function. Your script is all good.

1 Like

@tralalah @SilentsReplacement

I’ve tried both of your ideas, none of them worked. I added a return at the end of my first if-statement because they both ran. Now only one of them runs, but I still have the same problem.

I’ve also tried prints, but the only part of the code that runs properly is the first if-statement. I already know that runs properly so there’s no point for print statements.

local PlayerGui = game.Players.LocalPlayer.PlayerGui
local TransparentLayer = PlayerGui:WaitForChild("Application")["Base"]["Transparent Layer"]
local IntroductionTemplate = TransparentLayer["Introduction Template"]
local ReadyButton = IntroductionTemplate:FindFirstChild("ReadyButton")
local NextButton = TransparentLayer["Question Template"]["NextButton"]

IntroductionTemplate.Visible = true

local SavedAnswers = {}

local TimeLimit = 300
local NotedTimeLimit = 300

local function BaseFunction(QuestionNum, Question)
	local QuestionString = "Q"..QuestionNum..". "..Question
	local QuestionTemplate = TransparentLayer["Question Template"]

	if IntroductionTemplate then
		local HidingPos = UDim2.new(2,0,0,0)
		local TargetPos = UDim2.new(0.012,0,0,0)
		IntroductionTemplate:TweenPosition(HidingPos, "Out", "Quint", 1)
		repeat wait() until IntroductionTemplate.Position == HidingPos
		IntroductionTemplate:Destroy()
		
		local QuestionBox = QuestionTemplate.QuestionBox
		QuestionBox.Text = QuestionString
		
		QuestionTemplate.Visible = true
		QuestionTemplate:TweenPosition(TargetPos, "Out", "Quint", 1)
		return
	end
	
	if TransparentLayer:FindFirstChild("Question Template") then
		local Question = TransparentLayer:FindFirstChild("Question Template")
		local HidingPos = UDim2.new(2,0,0,0)
		local TargetPos = UDim2.new(0.012,0,0,0)
		Question:TweenPosition(HidingPos, "Out", "Quint", 1)
		repeat wait() until Question.Position == HidingPos
		
		local QuestionBox = Question.QuestionBox
		QuestionBox.Text = QuestionString
		
		Question.Visible = true
		Question:TweenPosition(TargetPos, "Out", "Quint", 1)
	end
end

function OnNBClick()
	print("got to the clicked function")
	local Times = 0
	if Times == 0 then
		Times = Times + 1
		BaseFunction("2", "Why do you choose to work at Reiné over other companies?")
	elseif Times == 1 then
		Times = Times + 1
		BaseFunction("3", "Why do you feel like you should be accepted over other applicants & what special abilities do you possess?")
	elseif Times == 2 then
		Times = Times + 1
		BaseFunction("4", 'Correct this sentence: Hay welcome to rénay cafwe. Im gladd too be takinq youre ordier todeay howw may i helpp!')
	end
end

function sendTrelloResults()
	
end

if TransparentLayer:FindFirstChild("Introduction Template") then
	local IntroductionTemplate = TransparentLayer:FindFirstChild("Introduction Template")
	local ReadyButton = IntroductionTemplate:FindFirstChild("ReadyButton")
	ReadyButton.MouseButton1Click:Connect(function()
		BaseFunction("1", "If you were to greet a customer at the cafe, what would be your greeting?")
	end)
end

NextButton.MouseButton1Click:Connect(OnNBClick)
1 Like

What about saying NextButton.MouseButton1Click:Connect(function(). I usually this when function() doesn’t work…

2 Likes

Still doesn’t work. Really odd. :woman_shrugging:

NextButton.MouseButton1Click:Connect(function()
	print("got to the clicked function")
	local Times = 0
	if Times == 0 then
		Times = Times + 1
		BaseFunction("2", "Why do you choose to work at Reiné over other companies?")
	elseif Times == 1 then
		Times = Times + 1
		BaseFunction("3", "Why do you feel like you should be accepted over other applicants & what special abilities do you possess?")
	elseif Times == 2 then
		Times = Times + 1
		BaseFunction("4", 'Correct this sentence: Hay welcome to rénay cafwe. Im gladd too be takinq youre ordier todeay howw may i helpp!')
	end
end)
1 Like

Try to see what happens to your code with breakpoints.

2 Likes

Now this is really odd. I agree…

1 Like

Could you send a screenshot of the output? I’m seeing red, not sure if it is for the GUI but it would be helpful to know what it is.

Try adding a print statement here to see if its not a infinite loop

repeat wait() 
print("this is a test")
until IntroductionTemplate.Position == HidingPos
1 Like

Output

1 Like

It’s not an infinite loop.

[30chars]

2 Likes

Okay I have another question - how is it changing colours on-click if you can’t detect it?

1 Like

Whenever you hover over a button, Roblox automatically changes the color. There’s no code that does it, it’s just a feature for a TextButton.

1 Like

I see, I thought there might be another frame or something behind it; I guess I’m too used to doing that for my own UI.

I mean, if everything runs up to that event, but the event itself doesn’t call, then you should try the event in another script to see if it is an internal issue. Otherwise it has to be something stopping the event from being defined; i.e., something is stopping your code from running at some point.

Alright. I think I got somewhere. The correct parent for this button should be Question Template. I added this code to check the parent:

while wait(1) do
	print(NextButton.Parent)
end

It kept printing the correct parent. When I hit the “Ready” button, it stopped printing. Does that mean the parent is nil?

1 Like

Where did u place that line?

[30chars]

1 Like