Help with GUI script

Hey hey :grinning: I am new to scripting and have hired a scripter to create a subtitle system for my theatre. I need to synchronize the subtitles with the in-game audio with wait(n). However, this is almost impossible, especially if you have to modify 1 piece. Then the rest will no longer be correct.

Is there a way to do this in an easy way? Or is there a function with which you can use wait from the 0 moment each time? Example:

setText(“Girls, boys, ladies, gentlemen. In short, honoured public”)
wait(6) – 6 seconds in audio
setText(“I come here to tell you a story”)
wait(13) – 13 seconds in audio, instead of the wait(7)

Ill post all my scripts below

GUI getting activated via a part in workspace + click detector

local db = false
script.Parent.MouseClick:Connect(function(plr)
	if game.Players:FindFirstChild(plr.Name) then
		if not db then
			db = true
			game.ReplicatedStorage.audio1:FireAllClients()
			wait(50)
			db = false
		end
	end
end)

Localscript in Textlabel

local textLabel = script.Parent
local Text 

function setText(word)
	Text = word
	for i = 1, #Text do
		textLabel.Text = string.sub(Text,1,i)
	end
end

game.ReplicatedStorage.audio1.OnClientEvent:Connect(function()
	wait(8)
	script.Parent.Parent.Visible = true
	setText("Girls, boys, ladies, gentlemen. In short, honoured public")
	wait(6)
	setText("I come here to tell you a story")
	wait(7)
	setText("And I do so with many words and with beautiful music")
	wait(7)
	setText("But I won't do that without introducing myself here")
	wait(10)
	setText("I am Theodore, I was once head steward at a castle")
	wait(6)
	setText("A castle with kings and queens")
	wait(7)
	setText("Surely so much happened there every day")
	wait(7)
	setText("That's why I'll get to it very soon")
	wait(6)
	setText("Let's travel in time, just over 100 years")
	wait(6)
	setText("Yes, you are right, that is quite a while")
	wait(7)
	setText("And I already put here for you this great fairy tale book")
	wait(7)
	setText("'Tis the book. 'Tis the book about that dear Sleeping Beauty")
	wait(12) -- 101 sec in audio
	wait(14) -- Wait for next scene
	setText("Good morning, dear baker. Have you heard the big news? Yes, something happened again at the castle")
	wait(12)
	script.Parent.Parent.Visible = false
end)

Hello.

You can use spawn(function() to avoid wait functions from making other things wait in a script.

spawn(function()
  wait(2)
  print("Hey.") -- This will print later.
end)

print("Hello world"). -- This will print first.

Everything within the spawn(function() will be affected by the wait function. Everything outside of it won’t.

Wow thank you so much! This works great! I didn’t expect it to be so easy to fix. The script is looking like this right now. Is this the right way or can i shorten it maybe?

spawn(function()
	wait(74)
	setText("Yes, you are right, that is quite a while")
	end)
	
	spawn(function()
	wait(81)
	setText("And I already put here for you this great fairy tale book")
	end)
	
	spawn(function()
	wait(88)
	setText("'Tis the book. 'Tis the book about that dear Sleeping Beauty")
	end)
1 Like

This might not answer your latest reply, but please use task.wait() instead of wait().

Task Library - Now Available! - Updates / Announcements - DevForum | Roblox

In short: task.wait() is just a newer, updated version of wait()

Of course. I would say do something like this.

spawn(function()
    wait(74)
    setText("Yes, you are right, that is quite a while")

    wait(7)
    setText("And I already put here for you this great fairy tale book")

    wait(7)
    setText("'Tis the book. 'Tis the book about that dear Sleeping Beauty")
end)
1 Like

Thank you! It’s a lot cleaner now haha. The only problem is that players only see the text/subtitles when they are in-game at the moment the script is activated. Example: audio 1 with GUI is activated and a player joins the game 2 mins after, he/she sees nothing (but can hear the audio). Do you, or anyone else, know a way to solve this? I think it has something to do with ReplicatedStorage, but am not sure.

Hello.

This is due to replication. I’m assuming the text script is on the client, while the audio is on the server. The audio will be the same for everyone in the server since it’s server-to-client replication.

To fix this; if you want everyone to have the same text at the same time you’d have to use remote-events from server to client for the text and audio. If you want everyone to have their own time with audio and text, just create the audio on the client.

why don’t you use Sound.Ended:Wait()? unless it’s all one sound

Heyy! I’ve never heard of this before. Can I apply this for the wait function, or to solve the problem with the replicatedstorage/remote events? I have 7 audio assets with 7 GUI scripts for the subtitles. Ive tried the remote event script (local and normal) for server to client, but ppl still don’t see the subtitles when they join later

It’s just for the wait problem since all but if you already got the voice and text synced then it doesn’t matter just replace your waits with sound.Ended:Wait() I don’t understand what your problem is with the remote events if you could give me more details about that then maybe I could help you

The subtitles are connected to a RemoteEvent and are played when a button is pressed. The text is then visible to everyone except people who join later. I have therefore created audio1remote in ServerScriptService and StarterPlayerScripts. However, the subtitles are not visible if the button is pressed and someone joins later. I copied the scripts like the example below.

sorry for late reply I think you could just send a remote event that tells the player what subtitles and sound and time position of that sound it should be on when a player joins late