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
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?
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
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);
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())
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.
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.