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

Why doesn't my script work? Its inside a gui maybe a local script is needed?


local Txt = script.Parent
while true do
Txt.Text = ("Role Call")
	wait(120)
Txt.Text = ("Free Period")
	wait(600)
Txt.Text = ("Lunch Period")
	wait(300) 
Txt.Text = ("Cell Time")
	wait(360)
Txt.Text = ("Short Free Period")
	wait(300)
Txt.Text = ("Sleep Period")
	wait(480)
end

Ok so this script is in a Gui. Which has some text in. Txt is the text box which changes the text. For some odd reason it changes To role call but not after 2 minutes (120secs) it doesn't change to free period. Please help me.

3 answers

✓ Accepted answer

First off, you don't want the parenthesis encapsulating the string when setting the text of Txt. And second, when scripting guis, you ALWAYS want to work with local scripts. Also, check the output for errors.

Of course, use a local script. ServerScript can not or should not access a GUI. Change it to a local script.

Here are some changes for your script:

local TextLabel = script.Parent
local Looper = true

while Looper = true do
	TextLabel.Text = ('Role Call')
	wait(120)
	TextLabel.Text = ('Free Period')
	wait(600)
	TextLabel.Text = ('Lunch Period')
	wait(300)
	TextLabel.Text = ('Cell Time')
	wait(360)
	TextLabel.Text = ('Short Free Time')
	wait(480)
end

If this helped in some sort of way, please Upvote and accept answer

-your Orange, BlackOrange3343

Both Answers above are correct answers, However I am going to suggest some changes.

When users join whatever text is there will be different for each one of them as their timer would be off.

Create a script in ServerScriptService and create a StringValue in ReplicatedStorage.

from there the script in the GUI should be a localscript, while the script in the ServerScriptService should be just a regular script (aka a server script)

Script in ServerScriptService code:

local Text = game.ReplicatedStorage:WaitForChild("Value") -- Value should be any name as long it's type is a StringValue

while true do
Text.Value = "Role Call"
    wait(120)
Text.Value = "Free Period"
    wait(600)
Text.Value = "Lunch Period"
    wait(300)
Text.Value = "Cell Time"
    wait(360)
Text.Value = "Short Free Period"
    wait(300)
Text.Value = "Sleep Period"
    wait(480)
end

LocalScript in GUI code:

local Txt = script.Parent
local Info = game.ReplicatedStorage.Value.Value -- replace 'value' with the name of the StringValue in ReplicatedStorage

Info.Changed:Connect(function() 
	-- call a function if anything of "Info" is changed
      Txt.Text = Info.Value
end)

A LocalScript can access anything in ReplicatedStorage, think of it like a shared space between the server and the client.

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