My game won't update the text of a screen GUI

So I am creating a capture the flag game and I am working on scripting the flags right now. I am almost done however I am working on making it so that when a player takes the flag a screen GUI pops up at the top of the screen and says “(player name) has stolen the (team) flag” and then when they bring it back to their base another message pops up and says “'(player name) has captured the (team) flag”
The way that I did this was make a string value is replicated storage called “Status” and whenever a player takes the flag or captures it, the string value is changed to what it needs to say. Then I have a local script in text label which makes the message appear and then slowly makes it disappear.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local displayValue = ReplicatedStorage:WaitForChild("DisplayValues")
local status = displayValue:WaitForChild("Status")
local textLabel = script.Parent

status.Changed:Connect(function()
	textLabel.Text = status.Value
	wait(2)
	while true do
		textLabel.TextTransparency = textLabel.TextTransparency + .02
		textLabel.TextStrokeTransparency = textLabel.TextStrokeTransparency + .01
		wait(.05)
	end
	wait(1)
	textLabel.Text = " "
	textLabel.TextTransparency = 0
	textLabel.TextStrokeTransparency = 0.5
	
end)

The issue I am having is that the first time a player takes the flag the message shows up, but then the second time it happens it doesn’t update. The string value is still being changed but it just isn’t showing up on the GUI.

Make it print everytime it changes

1 Like

Ok so I made it print and now it prints each time it changes but it still doesn’t change the GUI

Let me know if this works

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local displayValue = ReplicatedStorage:WaitForChild("DisplayValues")
local Status = displayValue:WaitForChild("Status")
local textLabel = script.Parent

Status.Changed:Connect(function)
textLabel.Text = Status.Value
end)

in the status.change you have a while loop in it so it will loop infinitely so that why when the second person touch the flag it dont show up becuase it still looping

1 Like

I think the problem here is that you’re not changing the TextTransparency back to 0, which makes it look like it’s not changing.

Also, the while true do loop will keep running, even if the script is done executing. So the TextTransparency never gets set back to 0

Try this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local displayValue = ReplicatedStorage:WaitForChild("DisplayValues")
local status = displayValue:WaitForChild("Status")
local textLabel = script.Parent

status.Changed:Connect(function()
	textLabel.Text = status.Value -- right here
	textLabel.TextStrokeTransparency = 0
	wait(2)
	while textLabel.TextStrokeTransparency == 0 do -- and here
		textLabel.TextTransparency = textLabel.TextTransparency + .02
		textLabel.TextStrokeTransparency = textLabel.TextStrokeTransparency + .01
		wait(.05)
	end
	wait(1)
	textLabel.Text = " "
	textLabel.TextTransparency = 0
	textLabel.TextStrokeTransparency = 0.5

end)
1 Like