I'm trying to make it so that once a video is over, another random one plays. I made an infinite loop, and an RNG from 1-10 which makes the video's ID change based on what it returns. I made the thread yield until the video was over using wait(Video.TimeLength)
. I don't know if the TimeLength
changes based on the ID of the video, so that could possibly be the problem. The script I wrote is parented to the screen part of the TV.
This is the script:
while true do local TimeToWait = script.Parent.SurfaceGui.Video.TimeLength local RandomNumber = math.random(1,10) local Video = script.Parent.SurfaceGui.Video wait(TimeToWait) if RandomNumber == 1 then Video.Video = "rbxassetid://5608342423" elseif RandomNumber == 2 then Video.Video = "rbxassetid://5608339667" elseif RandomNumber == 3 then Video.Video = "rbxassetid://5608333583" elseif RandomNumber == 4 then Video.Video = "rbxassetid://5670822962" elseif RandomNumber == 5 then Video.Video = "rbxassetid://5608370112" elseif RandomNumber == 6 then Video.Video = "rbxassetid://5608359401" elseif RandomNumber == 7 then Video.Video = "rbxassetid://5670802294" elseif RandomNumber == 8 then Video.Video = "rbxassetid://5608368298" elseif RandomNumber == 9 then Video.Video = "rbxassetid://5670824523" elseif RandomNumber == 10 then Video.Video = "rbxassetid://5608369138" end end
Thanks in advance!
TimeLength indeed does change based on video ID, my answer won't be complete because I don't want to but it will make your script partially work. First, in Explorer change the Playing property of the Video frame to false (uncheck the checkbox), it did create some issues for me which could break the video after few plays, you are going to manually play the video in the script. Next thing you should do is put TimeLength after you changed the video's ID because if you do it before, Roblox does not know which video is going to be played and so it can't know it's length, but between that you should also wait until the video is loaded, otherwise TimeLength will be 0, you can do that easily too:
-- i put this variable here because there is no -- need to put it into the loop, however it does -- not matter actually local Video = script.Parent.SurfaceGui.Video while true do local RandomNumber = math.random(1,10) if RandomNumber == 1 then Video.Video = "rbxassetid://5608342423" elseif RandomNumber == 2 then Video.Video = "rbxassetid://5608339667" elseif RandomNumber == 3 then Video.Video = "rbxassetid://5608333583" elseif RandomNumber == 4 then Video.Video = "rbxassetid://5670822962" elseif RandomNumber == 5 then Video.Video = "rbxassetid://5608370112" elseif RandomNumber == 6 then Video.Video = "rbxassetid://5608359401" elseif RandomNumber == 7 then Video.Video = "rbxassetid://5670802294" elseif RandomNumber == 8 then Video.Video = "rbxassetid://5608368298" elseif RandomNumber == 9 then Video.Video = "rbxassetid://5670824523" elseif RandomNumber == 10 then Video.Video = "rbxassetid://5608369138" end -- wait until the video is not loaded, otherwise -- TimeLength will be 0 since you don't know -- length of an unloaded video ): -- and don't wait for the video to load if it is -- already loaded, that's the 'if not Video.IsLoaded' if not Video.IsLoaded then Video.Loaded:Wait() end -- since you disabled Playing, it won't auto play -- that's why you need to play it manually Video:Play() local TimeToWait = script.Parent.SurfaceGui.Video.TimeLength wait(TimeToWait) end
This will probably work but one more thing I can add to this is that when the random number generated will be equal to the previous one, the script may break, that's why I check for such cases, and if the random number is same as the previous one, I increase the random number by 1 (and if the random number is 10, increasing it by 1 would be 11 so I instead reset it to 1).
local Video = script.Parent.SurfaceGui.VideoFrame -- currently the previous random number was not -- yet generated so i set it to 0, can be any number, -- maybe -math.pi / 2 local PreviousRandomNumber = 0 while true do local RandomNumber = math.random(1,10) if RandomNumber == PreviousRandomNumber then -- this % 10 thing will reset RandomNumber to 0 if -- it is 10 RandomNumber = RandomNumber % 10 + 1 end PreviousRandomNumber = RandomNumber if RandomNumber == 1 then Video.Video = "rbxassetid://5608342423" elseif RandomNumber == 2 then Video.Video = "rbxassetid://5608339667" elseif RandomNumber == 3 then Video.Video = "rbxassetid://5608333583" elseif RandomNumber == 4 then Video.Video = "rbxassetid://5670822962" elseif RandomNumber == 5 then Video.Video = "rbxassetid://5608370112" elseif RandomNumber == 6 then Video.Video = "rbxassetid://5608359401" elseif RandomNumber == 7 then Video.Video = "rbxassetid://5670802294" elseif RandomNumber == 8 then Video.Video = "rbxassetid://5608368298" elseif RandomNumber == 9 then Video.Video = "rbxassetid://5670824523" elseif RandomNumber == 10 then Video.Video = "rbxassetid://5608369138" end if not Video.IsLoaded then Video.Loaded:Wait() end Video:Play() local TimeToWait = script.Parent.SurfaceGui.VideoFrame.TimeLength wait(TimeToWait) end
The reason why this script is incomplete is because you will still see small white screens between the videos, that's because until the next video does not load, there will be white screen. That can be fixed by making some kind of fade in fade out start 0.5 seconds before the end of the video, I see some other solutions too but I won't write it here [: