✓ Accepted answer
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:
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
if not Video.IsLoaded then
Video.Loaded:Wait()
end
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
local PreviousRandomNumber = 0
while true do
local RandomNumber = math.random(1,10)
if RandomNumber == PreviousRandomNumber then
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 [:
3 comments
Hey! Have you errors in output?
No
However, It's not that it actually isn't working, but that the screen goes white for a second, and the next video doesn't play for a while