Value doesn't detect change?

Hi! I am trying to make a system so when the value changes it will change the text, however for some reason when the value is changed the print right after the .Changed line doesn’t print. I can’t find out why. Any Ideas?

Code
    wait(5)
    local LessonText = script.LessonText.Value
    local text =  script.Parent.Welcome:WaitForChild("welcomeText").Text

    print("Got variables")

    for i=1, #text do
	
	wait(.1)
	script.Parent.Welcome.welcomeText.Text = string.sub(text,1,i)
	
    end

    wait(5)

    script.Parent.Welcome.Visible = false
    script.Parent.Class1.Visible = true
     print("Class1 is now visible...")
    LessonText = LessonText+1
    local Class1MT = script.Parent.Class1.mainText


    script.Parent.Class1.Next.MouseButton1Click:Connect(function()
	print("Button Clicked")
	LessonText = LessonText + 1
	
    end)

    script.LessonText.Changed:Connect(function()
	print("ChangedValue!")
	
    if LessonText ==  1 then
	print("L1")
    Class1MT.Text = "No matter your age, background, or experience, effective communication is a skill you can learn. The greatest leaders of all time are also fantastic communicators and orators. In fact, communications is one of the most popular college degrees today; people recognize the value of a truly efficient communicator. With a little self-confidence and knowledge of the basics, you'll be able to get your point across in no time."
    wait(25)
    LessonText = 2
  
    elseif LessonText ==  2 then
	print("L2")
    Class1MT.Text = "Let's go over the basics.  While you're talking to another staff member or inmate, you should face them directly and speak with grammar/punctuation at all times. This shows that you are listening and you are open to communication."
    wait(10)
    LessonText = 3

    elseif LessonText == 3 then
	
    Class1MT.Text = "Grammar skills are useful in every aspect of life from education to leadership, and social life to employment opportunities. ... Proper grammar is also essential for understanding English as a second language as well as for learning a new language, since all languages follow grammatical patterns."
    wait(15)
    LessonText = 4

    elseif LessonText == 4 then
	
    Class1MT.Text = "Why is it important to use punctuation in typing? The key is to get students to understand that punctuation is for the reader, not the typer. Punctuation aids the reader in understanding the typer's intended message. Sometimes the use of punctuation (like end marks) makes it easier to read and comprehend typed ideas."
    wait(15)
    LessonText = 5

    elseif LessonText == 5 then
	print("L5")
	script.Parent.Class1.Lesson.Text = "Lesson 2 : Negotiation"
	
	Class1MT.Text = "A negotiation is a strategic discussion that resolves an issue in a way that both parties find acceptable. In a negotiation, each party tries to persuade the other to agree with his or her point of view. By negotiating, all involved parties try to avoid arguing but agree to reach some form of compromise"
	wait(15)
	LessonText = 6
	
	elseif LessonText == 6 then
Class1MT.Text = "Stages of Negotiation.. In order to achieve a desirable outcome, it may be useful to follow a structured approach to negotiation. For example, in a situation a meeting may need to be arranged in which all parties involved can come together."
wait(15)
LessonText = 7

elseif LessonText == 7 then
	print("L7")
Class1MT.Text = "The process of negotiation includes the following stages: Preparation - Discussion - Clarification of goals - Negotiate towards a Win-Win outcome - Agreement - Implementation of a course of action"
wait(15)
LessonText = 8

elseif LessonText == 8 then
Class1MT.Text = "Before any negotiation takes place, a decision needs to be taken as to when and where a meeting will take place to discuss the problem.  Setting a limited time-scale can also be helpful to prevent the disagreement continuing."
wait(15)
LessonText = 9

elseif LessonText == 9 then
Class1MT.Text = "Preparation : Before any negotiation takes place, a decision needs to be taken as to when and where a meeting will take place to discuss the problem.  Setting a limited time-scale can also be helpful to prevent the disagreement continuing."
wait(15)
LessonText = 10

elseif LessonText == 10 then
Class1MT.Text = "Discusson : During this stage, individuals or members of each side put forward the case as they see it, i.e. their understanding of the situation."
wait(15)
LessonText = 11

elseif LessonText == 11 then
Class1MT.Text = "Clarifying Goals : From the discussion, the goals, interests and viewpoints of both sides of the disagreement need to be clarified."
wait(15)
LessonText = 12

elseif LessonText == 12 then
Class1MT.Text = "The more knowledge you possess of the issues in question, the greater your participation in the process of negotiation.  In other words, good preparation is essential."
wait(15)
LessonText = 13

elseif LessonText == 13 then
	
		script.Parent.Class1.Lesson.Text = "Lesson 1"
	
	Class1MT.Text = "You have finished this tier. Please wait as I transfer you to the quiz..."
	wait(5)
	script.Parent.Class1.Visible = false
	script.Parent.Quiz.Visible = true
	
	
	

end
end)





6 Likes

You don’t have to do spaces every line:


print(‘Hello World’)

image

i’m going to type an answer to your issue in a min bare withs

1 Like

It is because you have .Value on the end of your variable. Remove it and put it on where you change or read the value.

2 Likes

Lua stores LessonText as the value at the time the variable is set. You’ll need to change LessonText to reference the instance itself, and use ‘.Value’ to check it.

1 Like

@ElliottLMz Thanks for the helpful tip on code! That makes things so much easier.

@xXStevenTheGreatXx

When I do get the changed, I do

script.LessonText.Changed:Connect(function()

end)

I decided to put the .Value for the variable because I didn’t want to go all the way back through the code and add .Value… Lazy, I know.

@ElliottLMz

So, should I do… script.Lesson.Value.Changed?

2 Likes

LessonText.Value will reference the current value.
LessonText.Changed will fire when the value is changed.

LessonText.Value is not an instance and doesn’t have any events!

3 Likes

whilst that helps, I still need an answer that’d find out why the changed event doesn’t work :confused:

1 Like

Can you clarify why it isn’t working? Is the event not getting fired at all?

It would be helpful if you could provide an .rbxl file.

1 Like

Well when the value gets changed, the code doesn’t detect the change.

script.Parent.Button.MouseButton1Click:Connect(function()

Value.Value = Value.Value + 1
print("Changed value")

end)

-- Changed

Value.Changed:Connect(function()
print("GotChanged") -- Never prints

if blah blah blah == blah

end)

I don’t feel good about posting a Rbxl file as there’s a whole system and i don’t feel like it’d be a good/safe idea for me to put it here.

1 Like

An issue I’ve noticed straight away is that you don’t accept the callback that .Changed provides. The event will give you the property of what has changed.

SomeValue.Changed:Connect(function(Change)
  print("Change:", Change)
end)

What you should do in your code is accept this and then change the appropriate pieces to support it.

Here is a tiny example with your current code which you’ve provided on the original post (obviously this is missing things):

script.LessonText.Changed:Connect(function(Change)
  if Change == 1 then
    print("L1")
  elseif Change == 2 then
    print("L2")
  -- and so on
  end
end)

The reason your current code does not work is because you store the value of LessonText initially and it is never changing, so your “if statements” are not true.

6 Likes

I’ve fixed some errors with the code itself.

script.Parent.Button.MouseButton1Click:Connect(function()
    Value.Value = Value.Value + 1 -- I don't recommend naming the instance "Value" - it is likely to become confusing
    print("Changed value")
end)

-- Changed

Value.Changed:Connect(function()
    print("GotChanged") -- Never prints
end -- you needed an "end" here

if blah blah blah == blah then -- you needed a "then" here

end)
1 Like

He was providing example code. That was not meant to work.

1 Like

that’s a very simplified version of the code so it’s not going to be up to usual standards.

I put the if blah blah blah whatever inside the changed event because when the value is changed, I want to check if the value is this or that.

The real code is in the post

1 Like

Ah, okay. Never mind then. Thanks for the heads up - and kudos, I’d forgotten about the fact that .Changed has the actual changed value as an argument.

1 Like