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 loop a script or part of the script? I need help!

So, basically, I need to know how to loop my script. I'm making a countdown for my game, and it's actually important to the game. Here's the script I want to repeat:

--//Variables
local DuelGUI = script.Parent.Parent
local Script = script.Parent.DuelHandler
local CountdownVal = script.Parent.Countdown
local YesandNoFrame = script.Parent.YesAndNo
local DuelTextText = script.Parent.DuelText
local DuelStartingCountdownVal = script.Parent.DuelStartingCountdown
local Player = script.Parent.Parent.Parent.Parent

--//The coding part
repeat wait()
	wait(1)
	CountdownVal = CountdownVal - 1
	DuelTextText.Text = "Duel starting in "..CountdownVal "..."
until CountdownVal == 0

if CountdownVal == 0 then
	DuelTextText.Text = "A duel is starting in "..CountdownVal " seconds. Would you like to enter? 5 players max."
end

repeat wait()
	wait(1)
	DuelStartingCountdownVal = DuelStartingCountdownVal - 1
	DuelTextText.Text = "Duel in progress... "..CountdownVal " seconds left"
until DuelStartingCountdownVal == 0

if DuelStartingCountdownVal == 0 then
	-- This part, I need to repeat
end

On line 28, i need it to loop the script, or just loop from line 10 to 29 over and over again. But I don't know how to do it. While true do, perhaps? Here's a screenshot of where everything is located: https://bit.ly/2Y7IFL7 If anyone can help, please do. Thanks =)

1 comment

0

Are you using a Server Script in the GUI? If you are, use a local script. Also, you can use repeat until() for the part you need to loop.

1 answer

✓ Accepted answer

Here

--//Variables
local DuelGUI = script.Parent.Parent
local Script = script.Parent.DuelHandler
local CountdownVal = script.Parent.Countdown
local YesandNoFrame = script.Parent.YesAndNo
local DuelTextText = script.Parent.DuelText
local DuelStartingCountdownVal = script.Parent.DuelStartingCountdown
local Player = script.Parent.Parent.Parent.Parent

--//The coding part
repeat wait()
    wait(1)
    CountdownVal = CountdownVal - 1
    DuelTextText.Text = "Duel starting in "..CountdownVal "..."
until CountdownVal == 0

if CountdownVal == 0 then
    DuelTextText.Text = "A duel is starting in "..CountdownVal " seconds. Would you like to enter? 5 players max."
end

    wait(1)
    DuelStartingCountdownVal = DuelStartingCountdownVal - 1
    DuelTextText.Text = "Duel in progress... "..CountdownVal " seconds left"
until DuelStartingCountdownVal == 0

if DuelStartingCountdownVal == 0 then
while true do
	print("Looping...")
	wait(0.5)
	end
end

3 comments

0

@Officer_DuckyC ok.. but can you grab my script and put it inside there? I'm tired, and I can't really focus while I am. Thanks anyway =)

0

k

0

Fixed

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