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

How do I make this work on a SurfaceGui and repeat it over and over again?

I made this script using it as a GUI for my Intro to my game. Well, I didn't want to do that anymore since it looked, well, maybe terrible to others. But, now I wanted to make it like a story on something, so I replaced the gui to surfacegui and added all the things in it. This is how the Workspace is laid out and the script:

Workspace Lay-out:

--Workspace
  --Part
   --Intro(SurfaceGui)
    --Intro(Script)
     --Play(BoolValue)
    --Frame
       --Story(TextLabel)
       --Title(TextLabel)

Script:

print("Intro is loaded!")
local credits = "" -- Names of robloxians who worked on your game
local story = "Enjoy the game and buy whatever you like. Be sure to comment for any more ideas or anything you want to sell. Give it a thumbs up and/or fav it. Enjoy!" -- Intro story.
function PlayStory(label, frame, story)
	for i = 0, 1, 0.1 do
		frame.Title.TextTransparency = i
		frame.Title.TextStrokeTransparency = i
		label.TextTransparency = i
		label.TextStrokeTransparency = i
		wait(0.1)
	end
	
	label.Text = ""
	label.TextXAlignment = "Left"
	label.TextYAlignment = "Top"
	label.Size = UDim2.new(1, 0, 1, 0)
	for i = 1, 0, -0.1 do
		label.TextTransparency = i
		label.TextStrokeTransparency = i
		wait(0.01)
	end
	for thestring in string.gmatch(story, ".") do
		label.Text = label.Text..thestring
		wait(0.15)
	end
	for i = 0, 1, 0.1 do
		frame.BackgroundTransparency = i
		label.TextTransparency = i
		label.TextStrokeTransparency = i
		wait(0.1)
	end
	frame.Visible = false
end
local p = script.Parent.Parent.Parent.Parent
local val
if not p:FindFirstChild("Play") then
	val = script.Play
	val.Parent = p
else
	val = p.Play
end

if val.Value == true then
	val.Value = false
	wait(1)
	PlayStory(script.Parent.Story, script.Parent, story)
else
	script.Parent.Visible = false
end

1 comment

0

I'm allergic to people who want me to help on a script that is 50 lines or more.

1 answer

✓ Accepted answer

You have a logic problem in the PlayStory function: you fade out the text, replace the story (but over a long period of time; adding one character at a time to the invisible label) before finally fading in the entire story.

By "repeat it over and over again", I will assume you mean "how do I loop the story so that it plays indefinitely".

One option is to just put the PlayStory function (and the nearby 'if' statements) in a while loop that goes on forever (with a wait(1) command to prevent freezing).

If you want the story to only run when the "Play" boolean value is true, then connect the function to a Changed property (that is, put lines 43+ in a function that is called whenever "Play" changes):

val.Changed:connect(function()
	if val.Value == true then
	    val.Value = false
	    wait(1)
	    PlayStory(script.Parent.Story, script.Parent, story)
		wait(1)
	    script.Parent.Visible = false
	end
end)

Alternatively, there's the method where you show one sentence at a time (and let each fade out/in).

Here is the script for this alternative method:

print("Intro is loaded!")
local credits = "" -- Names of robloxians who worked on your game
local story = "Enjoy the game and buy whatever you like. Be sure to comment for any more ideas or anything you want to sell. Give it a thumbs up and/or fav it. Enjoy!" -- Intro story.
function PlayStory(label, frame, segment)
    for i = 0, 1, 0.1 do
        frame.Title.TextTransparency = i
        frame.Title.TextStrokeTransparency = i
        label.TextTransparency = i
        label.TextStrokeTransparency = i
        wait(0.1)
    end

    label.Text = ""
    label.TextXAlignment = "Left"
    label.TextYAlignment = "Top"
    label.Size = UDim2.new(1, 0, 1, 0)
    for i = 1, 0, -0.1 do
        label.TextTransparency = i
        label.TextStrokeTransparency = i
        wait(0.01)
    end
	label.Text = segment
    for i = 0, 1, 0.1 do
        frame.BackgroundTransparency = i
        label.TextTransparency = i
        label.TextStrokeTransparency = i
        wait(0.1)
    end
end

while true do
	for segment in string.gmatch(story, "[^.!?]*[.!?]*") do
	    PlayStory(script.Parent.Story, script.Parent, story)
	    wait(4)
	end
end

To make string.gmatch match an entire sentence, we use this: string.gmatch(story, "[^.!?][.!?]") The [^.!?] means "any character not a period, exclamation mark, or question mark" (the ^ means "not any of the following characters"), the * means "as many of these as possible", and then the rest says "as many punctuation marks as possible".

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