Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

The text gui is not updating when I fire?

game.ReplicatedStorage.Remote.MusicAlert.OnClientEvent:connect(function(SongName)
	local Text = Gui.Notification.Text
	for i = 1, #SongName do
		Text = "Now playing: "..string.sub(SongName, 1, i)
		wait(0.1)
	end
end)

No errors when I send a string through the ().

2 comments

0

btw, when I print text in console it showed the updated text.

0

Fixed it, just don't use a variable and = it directly.

1 answer

✓ Accepted answer

I know you already fixed this, but I'd just like to give some basic insight as to why this happens.

Variables in RLua have many types (ex. Bool, String, Instance, etc.)

When you save a variable like you did before

Reference:

local Text = Gui.Notification.Text

It saves the Text property of the Instance as a String variable. This means that when you change it later in your code, it isn't changing the text that is on the TextLabel, it is changing the Text variable.

Example:

local textLabel = Instance.new('TextLabel')
textLabel.Text = 'foo'

local Text = textLabel.Text -- The variable "Text" now equals 'foo'

print(Text) -- Prints 'foo'

textLabel.Text = 'bar' -- We set the TextLabel's text to 'bar'

print(Text) -- Still prints 'foo'

The way to do what you were trying to do correctly (as you already found out) is to save the Text variable as the TextLabel's Instance. (Or just reference the TextLabel directly every time)

Example:

local textLabel = Gui.Notification
textLabel.Text = 'foo'

-- or just do

Gui.Notification.Text = 'foo'

Doing this allows you to change the instance's Text property directly, instead of what you did before (saving the text property as a variable).

1 comment

0

I FREAKING LOVE YOU NO HOMO.

This discussion is preserved as it was. New answers, comments, and votes are closed.