Why isnt my script working

Hello,

I was wondering if anyone could help me figure out why my script isn’t working. What I mean is the text in the text box wont change, every time i run my game the output doesn’t tell me any errors

local y = game.Workspace.Yes
local n = game.Workspace.No
local ask = script.Parent.SurfaceGui.Question.Text

y.ClickDetector.MouseClick:Connect(function()
	script.Parent.SurfaceGui.Question.Text = "Ok, Lets Begin"
	wait(5) 
	ask = "Are you relaxed"
	n.ClickDetector.MouseClick:Connect(function()
		ask = "Just relax"
		or
			y.ClickDetector.MouseClick:Connect(function()
			ask = "Good"
		end)
	end)
end)

Thank You For The Help :slight_smile:

From what I read of this code, the current function does the following:
Once you click “Yes” it asks the first question.

After that you give one option which is just “No”.

You would need to re-write it to give different options.

My bad, I was about to continue but I sent on accident.

Here:

y.ClickDetector.MouseClick:Connect(function()
	script.Parent.SurfaceGui.Question.Text = "Ok, Lets Begin"
	wait(5) 
	ask = "Are you relaxed"
	n.ClickDetector.MouseClick:Connect(function()
		ask = "Just relax"
	end)
	y.ClickDetector.MouseClick:Connect(function()
		ask = "Good"
	end)
end)

Even still I do not recommend making the code that way, but that bare code at least solves the problem you are having. In a full scale game I recommend coding it differently though.

Ok, Thank You. But how do i make it so that the code can detect what the question is? (What text is in the text box)

You shouldnt have an “or” statement in this case. You should put the y ClickDetector MouseClick event outside of the n one. Like so:

local n = game.Workspace.No
local ask = script.Parent.SurfaceGui.Question.Text

y.ClickDetector.MouseClick:Connect(function()
	script.Parent.SurfaceGui.Question.Text = "Ok, Lets Begin"
	wait(5) 
	ask = "Are you relaxed"
	n.ClickDetector.MouseClick:Connect(function()
		ask = "Just relax"
	end)
        y.ClickDetector.MouseClick:Connect(function()
               ask = "Good"
       end)
end)

Thank you i will change my script :slight_smile:

I tried changing my script and maybe i should’ve made it clearer in my question, i meant to ask why wont the text in the text box change after 5 seconds

That’s because you’re changing the variable and not the text inside the textbox (or textlabel). You should switch it to

ask.Text = "texthere"

You’re not setting the Text of the Question, you’re just changing the ask variable

local Question = script.Parent.SurfaceGui.Question

y.ClickDetector.MouseClick:Connect(function()
	Question.Text = "Ok, Lets Begin"
	wait(5) 
	Question.Text = "Are you relaxed"
	n.ClickDetector.MouseClick:Connect(function()
		Question.Text = "Just relax"
	end)
	y.ClickDetector.MouseClick:Connect(function()
		Question.Text = "Good"
	end)
end)

No, if you see his ask variable, it has .Text

That’s not the path to the text, the variable just stores what the text is, not the path to it.

I don’t understand what you want to do, do you want to do this?

local Question = script.Parent.SurfaceGui.Question
local DefaultText=Question.Text
game.Workspace.Yes.ClickDetector.MouseClick:Connect(function()
	if Question.Text=="Are you relaxed"then
		Question.Text="Good"
		wait(5)
		Question.Text=DefaultText
	elseif Question.Text==DefaultText then
		Question.Text="Ok, Lets Begin"
		wait(5)
		Question.Text="Are you relaxed"
	end
end)
game.Workspace.No.ClickDetector.MouseClick:Connect(function()
	if Question.Text=="Are you relaxed"then
		Question.Text="Just relax"
		wait(5)
		Question.Text=DefaultText
	end
end)

edit:
Because twice adding a function to the same event will also just fire the previously added ones I guess

Hello everyone,

Sorry for not saying this but i have solved the problem in my script