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

Why is this while loop erroring?

--[iLegimate]--

while true do
	wait()
	script.Parent.Text = game:GetService("ServerScriptService").MAINFRAME["HARD_DRIVE"].ValueStorage.ServerAnnouncer
end

OUTPUT :

06:32:21.815 - String expected
06:32:21.815 - Script 'Players.Player.PlayerGui.MAIN_TOPGUI.LOADING.Changer', Line 5
06:32:21.815 - Stack End

It should work..No idea why..So please help?

2 comments

1

What is "ServerAnnouncer" exactly? A string value object?

0

Yeah.

1 answer

✓ Accepted answer

Your Problem

On line 5, you're setting the Text property of script.Parent. The Text property must always be set as a string. It looks like in your code that you're setting the Text property to ServerAnnouncer - an object, or userdata, rather than actual text.


How To Fix

I'm going to make an assumption that ServerAnnouncer is a StringValue instance. If this is the case, then you just need to index it's Value property(:


Code

local severAnnouncer = game:GetService("ServerScriptService").MAINFRAME["HARD_DRIVE"].ValueStorage.ServerAnnouncer

while wait() do
	script.Parent.Text = serverAnnouncer.Value --Index the 'Value' Property
end

Alternative Suggestion

It looks like you're just trying to auto-update some text according to any changes in a stringvalue, correct? If so then I'm going to suggest using the Changed event to change the text. This event only activates when the value of the specified Value object changes - so it's much more efficient.

local severAnnouncer = game:GetService("ServerScriptService").MAINFRAME["HARD_DRIVE"].ValueStorage.ServerAnnouncer

serverAnnouncer.Changed:connect(function(change)
	script.Parent.Text = change --Set it to the change
end

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