Since roblox has implemented the new video feature, how could I create a loop for videos?
Like one video plays, another plays, and so on and so forth.
Since roblox has implemented the new video feature, how could I create a loop for videos?
Like one video plays, another plays, and so on and so forth.
I’m pretty sure that’s not what he is looking for, he wants it so consecutive videos will be played. Not 1 video to replay.
@CoolGuyBoiBruh, I just closed studio, please wait until I can help you with this. And also, don’t ask for free code!
Use.Ended to see when the last video has ended and then you can play the next one. If you want to loop through multiple videos then put them into a table and iterate through them on repeat waiting for the last one to end each time.
in the propeties of the video theres an option to loop the video
I know that. I am not trying to loop one video but multiple. Like one video plays, once it done, it goes to the next.
How could you execute to make a table? Would you use math.random to choose randome videos?
I dont think I asked for free code. Lol. I just wanted a starting point so I can execute the rest.
You can put all the video in a folder and then get a random video frame from it.
local folder = yourfolder:GetChildren()
local randomFrame = folder[math.random(1, #folder)]
Then play the video with video:Play()
you can use video.Ended:Wait() to add an wait for the video to end first. Then just repeat this process
I easily made my own little code that loops a bunch of videos and then when the current video has been finished it gets cloned to the ReplicatedStorage and vice versa, to further expand on this, here is little code I made:
local Videos = game.ReplicatedStorage.Videos:GetChildren() -- table that contains all of the videos
local MainPart = game.Workspace.MainPart -- the part that will have the video showed on
local SelectedVid = 0 -- the selected video within the table
while true do
if SelectedVid == #Videos then -- if the selected vid has reached the length of the table then restart it,
--meaning that if all of the videos in the table has been played then make it go back to the start
SelectedVid = 0
end
SelectedVid = SelectedVid + 1
local VideoName = Videos[SelectedVid].Name -- gets the video name from the table
game.ReplicatedStorage.Videos[VideoName].Parent = MainPart.SurfaceGui -- grabs the video from replicated storage and clone it to the part to play it on
local Vid = MainPart.SurfaceGui[VideoName] -- gets the current video
Vid:Play() -- Use the :Play() function to play the video
Vid.Ended:Wait(Vid.Video) -- waits until the current video has been ended with a parameter which accepts the video's id property
print("finished")
Vid.TimePosition = 0
Vid.Parent = game.ReplicatedStorage.Videos -- when finished clone it back to the replicated storage
Vid = nil -- set vid to nil so that it can iterate to the next video
wait(1)
end
If you are ever wondering why I didn’t destroy the video rather than cloning it back to RS, its because it sort of lagged dramatically and I like it this way anyway.
If this is too abstract for you then feel free to look for a simpler code.
Thanks for the help. Also, the roblox studio gave me this warning
At most 2 videos can play simultaneously.
That means only 2 can play at one time. So try to organise loading and playing videos efficiently to make it seamless.
ok then. I just organized it because i had 20 videos in the folder. So i decreased.
you dont have to decrease how many you have so long as you organise it. So load and play one video then while thats playing you can load the next one in so theres no waiting around. this also means you arent loading in more than 2 at a time.
I apologize for the late response but I had the same issue you were experiencing too, to prevent that error from executing on your output you can do the same technique so basically use a while loop but instead don’t clone videos just change the Video ID of it for every loop, here’s an example code:
local Videos = {"rbxassetid://5670794788", "rbxassetid://5608390467", "rbxassetid://5670826209"}
local MainPart = game.Workspace.MainPart
local SelectedVid = 0
while true do
if SelectedVid == #Videos then
SelectedVid = 0
end
SelectedVid = SelectedVid + 1
script.Parent.VideoFrame.Video = Videos[SelectedVid]
local Vid = script.Parent.VideoFrame
Vid:Play()
Vid.Ended:Wait(Vid.Video)
Vid:Pause()
Vid.TimePosition = 0
Vid = nil
wait(.5)
end
In this picture, I only added one videoframe which means I am only changing the ID of it rather than cloning another video and parenting it everytime, this is more sustainable.
Well, thanks again! This will really help later on.