Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can somebody explain to me why the second repeat doesn't work?

Asked by 5 years ago

The title is self explanatory:

local k = script.Parent
local s = script.Parent:FindFirstChild("Click")
local hm = script.Parent:FindFirstChild("vhs thing")
local other = script.Parent:FindFirstChild("Sound")
hm:Play()
wait(0.5)
k.Text = "W"
s:Play()
wait(0.5)
k.Text = "We"
s:Play()
wait(0.5)
k.Text = "Wel"
s:Play()
wait(0.5)
hm:Stop()
k.Text = "Welc"
s:Play()
other:Play()
wait(0.5)
k.Text = "Welco"
s:Play()
wait(0.5)
k.Text = "Welcom"
s:Play()
wait(0.5)
k.Text = "Welcome"
s:Play()
wait(1)
repeat wait(0.1) k.TextTransparency = k.TextTransparency + 0.1 until k.TextTransparency == 1
wait(3)
repeat wait(0.1) other.Volume = other.Volume - 0.1 until other.Volume <= 0
script.Parent.Sound.Volume = 0
script.Parent:Destroy()
0
you could make this code way better, check out loops on the wiki INOOBE_YT 387 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

This is because of conditional loops. Currently, the first loop is a wall for any code written prior to that loop. It has to break in order for newer code to run. A fix would be to use the spawn function, or just use a for loop!. And you don't have to manually set the text each time, use string.sub!

local welcome = "Welcome"

local k = script.Parent
local s = script.Parent:FindFirstChild("Click")
local hm = script.Parent:FindFirstChild("vhs thing")
local other = script.Parent:FindFirstChild("Sound")
hm:Play()
wait(0.5)

for i = 1, welcome:len() do
    wait(0.1)
    k.Text = welcome:sub(1, i) -- cool function that gives text typewriter effect
end

wait(1)

for i = 0.1, 1, 0.1 do -- loop the transparency 
    wait(0.1) 
    k.TextTransparency = i
end

wait(3)

for i = other.Volume, 0, -0.1 do -- loop at the volume to 0
    wait(0.1) 
    other.Volume = i

    if i <= 0 then -- if i is 0 destroy script.Parent
        script.Parent:Destroy()
        break 
    end
end

Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

The second loop could be

while true do
    other.Volume = other.Volume - 0.1
    wait(.1)
    if other.Volume == 0 then
        script.Parent:Destroy()
    end
end)
0
still doesn't work for some reason :/ Quibblish 9 — 5y
0
That is wrong. Repeat loops don't have a do neither do they have an end. User#19524 175 — 5y
0
I updated my script try it again it should work this time FirezoneGamez 155 — 5y

Answer this question