Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this while loop erroring?

Asked by
iLegitus 130
9 years ago
--[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?

1
What is "ServerAnnouncer" exactly? A string value object? Redbullusa 1580 — 9y
0
Yeah. iLegitus 130 — 9y

1 answer

Log in to vote
4
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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
Ad

Answer this question