Text not changing

Hello!

I am having trouble changing the text of a text label. The code does run without causing any errors so I am very confused.

Here’s the code:


local SpeechGUI = plr.PlayerGui:WaitForChild("ObjectiveGUI").SpeechFrame

if Objectvie7Finished.Value == true and Objectvie8Finished.Value == false then
	SpeechGUI.Visible = true
	SpeechGUI.Speech.Text = "DO NOT TRY TO LEAVE PEASANT!"
end

is that a script or a local script & where is it located?

The script is a server script in the workspace

i suggest you to use local scripts instead for playergui,texts

1 Like

Is “Objectvie7Finished” and “Objectvie8Finished” a dynamic value? As in, does it change because of an event in game?

First, consider just using a local script in the text label that is to change. There is no reason to get objects directly from the player’s GUI folder. Second, is your Object7Finished always true or false or does it change?

1 Like

It changes throughout the course of the game but I used print to make sure it ran and it did.

make a local script and put it in startergui
and i suggest you to do smth with the values cuz exploiters can easily change them since they’re running locaclly

local SpeechGUI = script.Parent:WaitForChild("ObjectiveGUI").SpeechFrame

if Objectvie7Finished.Value == true and Objectvie8Finished.Value == false then
	SpeechGUI.Visible = true
	SpeechGUI.Speech.Text = "DO NOT TRY TO LEAVE PEASANT!"
end
1 Like

I recommend binding an event instead. What is probably happening is that you are running this statement before the value is set to true:

Objectvie7Finished.Changed:Connect(function()
	if Objectvie7Finished.Value == true and Objectvie8Finished.Value == false then
		SpeechGUI.Visible = true
		SpeechGUI.Speech.Text = "DO NOT TRY TO LEAVE PEASANT!"
	end
end);

Edit: Also please use local scripts

1 Like

a better way to detect if both values are changed

function bothvalueschanged()
	if Objectvie7Finished.Value == true and Objectvie8Finished.Value == false then
		SpeechGUI.Visible = true
		SpeechGUI.Speech.Text = "DO NOT TRY TO LEAVE PEASANT!"
	end
end);
Objectvie7Finished.Changed:Connect(bothvalueschanged())
Objectvie8Finished.Changed:Connect(bothvalueschanged())
1 Like

That worked thx! I guess sometimes my brain turns off especially since I’ve been working on this project for a week straight 10 hours a day.

1 Like

That is why it is not working (aside from it being a server script). The script needs to detect the event change and run a function from there. Your script only checks the value once, at the start of the game.

If you put a local script into the text label, this code should fix that problem using the property changed event.

local speechGui = script.Parent.Parent
local speechText = script.Parent
-- Make sure to make a variable for the Object7 & Object8 values.
-- Also make sure this local script is inside of your speech text object.

Object7Finished:GetPropertyChangedSignal("Value"):Connect(function()
    if Object7Finished.Value == true and Object8Finished.Value == false then
        speechGui.Visible = true
        speechText.Text = "DO NOT TRY TO LEAVE PEASANT!"
    end
end)

As you can see, the GetPropertyChanged signal event is utilized as it will run our connected function each time the specified property is changed in any way.

By “any way,” it’s actually just the value. It runs when the value is changed.

The thing is, I believe that obj8 goes after obj7 as in they are steps. That is why I only binded obj7. But I mean if that is not the case then @ericmaster3392 use this.

This is not going to work if your value changes after the game first runs. Like I said previously, it will only work once the game has first started and if you change the values after that, it will not function. This only checks them once.

I took a small portion of the code because the entire script is too long but the changes suggested did work so thank y’all. : )

i don’t know when the Objectvie7Finished Value and Objectvie8Finished Value are going to change so yeah.

That’s why you connect them to an event. You don’t need to know when they’re going to change, it will know for you.

thats what i exactly did in here.

Remember that “Value.Changed” for base values is when the property “.Changed” changes. Not when Value as an Instance changes.