I made this simple countdown script by repeating things, but when I said like, one second, two second, it was like slower than I was counting. Plus I am making a countdown for the new game I am making which has a movie in it. I set the movie to start in 20 seconds, but it started 2 seconds early. This is the script:
local c = game.Workspace.Countdown.SurfaceGui.TextLabel while true do c.Text = 20 wait(1) c.Text = 19 wait(1) c.Text = 18 wait(1) c.Text = 17 wait(1) c.Text = 16 wait(1) c.Text = 15 wait(1) c.Text = 14 wait(1) c.Text = 13 wait(1) c.Text = 12 wait(1) c.Text = 11 wait(1) c.Text = 10 wait(1) c.Text = 9 wait(1) c.Text = 8 wait(1) c.Text = 7 wait(1) c.Text = 6 wait(1) c.Text = 5 wait(1) c.Text = 4 wait(1) c.Text = 3 wait(1) c.Text = 2 wait(1) c.Text = 1 wait(1) c.Text = 0 wait(1) c.Text = "Movie has Started!" wait(15) end
I am trying to get this start in this precise timing on this script (Thanks Goulstem for helping me this):
local bin = script.Parent local decal = bin.Decal local MainSlides = { ["1"] = {'http://www.roblox.com/asset/?id=213163470', 15}, ["2"] = {'http://www.roblox.com/asset/?id=213486920', 3}, ["3"] = {'http://www.roblox.com/asset/?id=157656296', 3}, ["4"] = {'http://www.roblox.com/asset/?id=213486967', 3}, ["5"] = {'http://www.roblox.com/asset/?id=151111211', 3}, ["6"] = {'http://www.roblox.com/asset/?id=213487020', 3} } function getNumTabs(tab) local num = 0 for i,v in pairs(tab) do num = num + 1 end return num end function runTable(tab) for i = 1,getNumTabs(tab) do local currentTab = tab[tostring(i)] decal.Texture = currentTab[1] wait(currentTab[2]) end end while wait() do runTable(MainSlides) end
When it says Movie has started, I put wait wait 15 secs. since 2-6 says 3 seconds, and 3 times 5 equals 15. I hope you understand what I am asking. I am not good at asking clearly :D
There's no reason for you use to use the strings "1", "2", ..., "6"
as the keys. Just use a list, ie, 1, 2, 3, ..., 6
local MainSlides = { {'http://www.roblox.com/asset/?id=213163470', 15}, {'http://www.roblox.com/asset/?id=213486920', 3}, {'http://www.roblox.com/asset/?id=157656296', 3}, {'http://www.roblox.com/asset/?id=213486967', 3}, {'http://www.roblox.com/asset/?id=151111211', 3}, {'http://www.roblox.com/asset/?id=213487020', 3} }
Now getNumTabs
isn't useful, since you can just use #MainSlides
to find out how many they are.
Even better, you can just use ipairs
for runTable
:
function runTable(tab) for _, slide in ipairs(tab) do decal.Texture = slide[1] wait(slide[2]) end end
First of all, use a for
loop for your countdown:
for timeLeft = 20, 0, -1 do -- Replaces the 40 lines of repetition! c.Text = timeLeft wait(1) end c.Text = "Movie has started!"
If you want the slide playback to match up with this, just put them in the same script!
-- (Define everything needed for runTable here, of course) local c = game.Workspace.Countdown.SurfaceGui.TextLabel function countDown() for timeLeft = 20, 0, -1 do -- Replaces the 40 lines of repetition! c.Text = timeLeft wait(1) end c.Text = "Movie has started!" end while true do countDown() runTable(MainSlides) end
not sure if this will help
local bin = script.Parent local decal = bin.Decal local SG = bin.SurfaceGui local Label = SG.Label local MainSlides = { -- ['rbxassetid://IMAGEID'] = WaitTime, ['rbxassetid://213163470'] = 15, ['rbxassetid://213486920'] = 3, ['rbxassetid://157656296'] = 3, ['rbxassetid://213486967'] = 3, ['rbxassetid://151111211'] = 3, ['rbxassetid://213487020'] = 3 } function runTable(tab) for image, time in pairs(MainSlides) do decal.Texture = image wait(time) end end -- Countdown for i=20, 0, -1 do Label.Text = i wait(1) end Label.Text = "Movie will now start!" wait(2) Label.Visible = false -- Movie Starts --Activate sequence while wait() do runTable(MainSlides) end --Edited by DragonSK16