How do i make this loop?

so i am trying to help my friend. so i am making a model for him. but i don’t know how to make it loop!

Local Script:

local debounce = false

for i, story in pairs(script.Parent:GetChildren()) do
	if story:IsA("ImageLabel") then
		if story.LayoutOrder == script.Parent.CurrentStory.Value then
			for i = 1,100 do
				wait()
				story.ImageTransparency -= 0.01
			end

			for i = 1, #story.Text.Value do
				story.TextLabel.Text = string.sub(story.Text.Value,1,i)
				wait(0.04)
			end

			story.Next.Visible = true
			for i = 1,100 do
				wait()
				story.Next.TextTransparency -= 0.01
			end

			story.Next.MouseButton1Click:Connect(function()
				if debounce == false then
					debounce = true

					script.Parent.CurrentStory.Value += 1

					for i = 1,100 do
						wait()
						story.ImageTransparency += 0.01
					end
					story.TextLabel.Text = ""

					for i = 1,100 do
						wait()
						story.Next.TextTransparency += 0.01
					end

					story.Next.Visible = true

					debounce = false
				end
			end)	
		end
	end
end

Put this in a RunService.Renderstepped loop.

Because it’s local, you can play these in a loop with a more fixed and accurate smooth style according to the players monitor.

It can be set up like this:

RunService = game:GetService ("RunService")
local debounce = false

RunService.RenderStepped:Connect(function(dt)

for i, story in pairs(script.Parent:GetChildren()) do
	if story:IsA("ImageLabel") then
		if story.LayoutOrder == script.Parent.CurrentStory.Value then
			for i = 1,100 do
				wait()
				story.ImageTransparency -= 0.01
			end

			for i = 1, #story.Text.Value do
				story.TextLabel.Text = string.sub(story.Text.Value,1,i)
				wait(0.04)
			end

			story.Next.Visible = true
			for i = 1,100 do
				wait()
				story.Next.TextTransparency -= 0.01
			end

			story.Next.MouseButton1Click:Connect(function()
				if debounce == false then
					debounce = true

					script.Parent.CurrentStory.Value += 1

					for i = 1,100 do
						wait()
						story.ImageTransparency += 0.01
					end
					story.TextLabel.Text = ""

					for i = 1,100 do
						wait()
						story.Next.TextTransparency += 0.01
					end

					story.Next.Visible = true

					debounce = false
				end
			end)	
		end
	end
end
end)

i tried renderstepped but all this did was make the showing up faster and made the text glitchy

You can also do task.wait()

while task.wait() do

end

well now the image doesn’t fully disappear and the text repeats itself once when clicked

Apologies for my stupidity because I just came in and tried to solve something with little to no knowledge of what you want to do. What exactly do you want it to do?

i want to make some sort of a story so that an image appears and once the image is fully visible the text will change and also when the text is changed fully a button to go to another part of the story appears. once the button is clicked the image, text and button disappears and the next part of the story is shown in the same way (hope i somewhat explained it)

local debounce = false

for i, story in pairs(script.Parent:GetChildren()) do
	if story:IsA("ImageLabel") then
		if story.LayoutOrder == script.Parent.CurrentStory.Value then
			repeat task.wait() story.ImageTransparency -= 0.01 until story.ImageTransparency == 0
			for i = 1, #story.Text.Value do
				story.TextLabel.Text = string.sub(story.Text.Value,1,i)
				task.wait(0.04)
			end

			story.Next.Visible = true
			repeat task.wait() story.Next.TextTransparency -= 0.01 until story.Next.TextTransparency == 0

			story.Next.MouseButton1Click:Connect(function()
				if debounce == false then
					debounce = true

					script.Parent.CurrentStory.Value += 1

					repeat task.wait() story.ImageTransparency += 0.01 until story.ImageTransparency == 1
					story.TextLabel.Text = ""

					repeat task.wait() story.Next.TextTransparency += 0.01 until story.Next.TextTransparency == 1


					story.Next.Visible = true

					debounce = false
				end
			end)	
		end
	end
end

You can just put them in a tween service, since it has a system of where it’s completed already and don’t have to write full on lines of code to do one thing.

Or do what he just did above.

Yeah. You can repeat change transparency until it is a certain amount, or you can use TweenService to tween the properties of an instance.

I have implemented TweenService into the script @H2ck0r10101 .

TweenService Script
local debounce = false
local TweenService = game:GetService("TweenService")

while task.wait() do
	for i, story in pairs(script.Parent:GetChildren()) do
		if story:IsA("ImageLabel") then
			if story.LayoutOrder == script.Parent.CurrentStory.Value then
				local Tween1 = TweenService:Create(story, TweenInfo.new(2), {ImageTransparency = 0})
				Tween1:Play()
				Tween1.Completed:Wait()
				Tween1:Destroy()
				for i = 1, #story.Text.Value do
					story.TextLabel.Text = string.sub(story.Text.Value,1,i)
					task.wait(0.04)
				end

				story.Next.Visible = true
				local Tween2 = TweenService:Create(story.Next, TweenInfo.new(1.5), {TextTransparency = 0})
				Tween2:Play()
				Tween2.Completed:Wait()
				Tween2:Destroy()
				story.Next.MouseButton1Click:Connect(function()
					if debounce == false then
						debounce = true

						script.Parent.CurrentStory.Value += 1

						local Tween3 = TweenService:Create(story, TweenInfo.new(2), {ImageTransparency = 1})
						Tween3:Play()
						Tween3.Completed:Wait()
						Tween3:Destroy()
						story.TextLabel.Text = ""

						local Tween4 = TweenService:Create(story.Next, TweenInfo.new(1.5), {TextTransparency = 1})
						Tween4:Play()
						Tween4.Completed:Wait()
						Tween4:Destroy()

						story.Next.Visible = true

						debounce = false
					end
				end)	
			end
		end
	end
end

To change the time it takes for the transparencies to change, just edit the number inside of: TweenInfo.new(2)

it is working! but there is unfortunatly one problem… when i click the button the text repeats itself

I do recommend this so that it doesn’t lag the player from the loops, but they both work fine.

Can you provide a GIF of what it’s doing for you?

New Script
local debounce = false
local TweenService = game:GetService("TweenService")

while task.wait() do
	for i, story in pairs(script.Parent:GetChildren()) do
		if story:IsA("ImageLabel") then
			if story.LayoutOrder == script.Parent.CurrentStory.Value then
				local Tween1 = TweenService:Create(story, TweenInfo.new(2), {ImageTransparency = 0})
				Tween1:Play()
				Tween1.Completed:Wait()
				Tween1:Destroy()
				for i = 1, #story.Text.Value do
					story.TextLabel.Text = string.sub(story.Text.Value,1,i)
					task.wait(0.04)
				end

				story.Next.Visible = true
				local Tween2 = TweenService:Create(story.Next, TweenInfo.new(1.5), {TextTransparency = 0})
				Tween2:Play()
				Tween2.Completed:Wait()
				Tween2:Destroy()
				local StoryNext
				StoryNext = story.Next.MouseButton1Click:Connect(function()
					if story.LayoutOrder == script.Parent.CurrentStory.Value then
						if debounce == false then
							debounce = true

							script.Parent.CurrentStory.Value += 1

							local Tween3 = TweenService:Create(story, TweenInfo.new(2), {ImageTransparency = 1})
							Tween3:Play()
							Tween3.Completed:Wait()
							Tween3:Destroy()
							story.TextLabel.Text = ""

							local Tween4 = TweenService:Create(story.Next, TweenInfo.new(1.5), {TextTransparency = 1})
							Tween4:Play()
							Tween4.Completed:Wait()
							Tween4:Destroy()

							story.Next.Visible = true

							debounce = false
							StoryNext:Disconnect()
							StoryNext = nil
						end
					end
				end)	
			end
		end
	end
end

Should work properly now. I just had check if the LayoutOrder was the proper one, and disconnect the button after it was clicked to prevent it from running multiple times.