How to choose random number from array

Hi! Im using video Ids to randomize what video will be played

VideoFrame = script.Parent

local Videos = {5608327482, 5608297917, 5608359401, 5608304953, 5608368298}
VideoFrame.Video = Videos[math.random(1,#Videos)]

This is what I currently have, but for some reason It dosent pick out a video and put it in the video Id. Im using VideoFrame | Roblox Creator Documentation To paste the id onto the videoframe

1 Like

You need to prefix the id with β€œrbxassetid://”

2 Likes

Like this? ```
rbxassetid://5608327482

yez​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

you can just do

VideoFrame.Video = "rbxassetid://" .. Videos[math.random(#Videos)]
2 Likes
VideoFrame.Video = "rbxassetid://" .. tostring(Videos[math.random(1,#Videos)])

To achieve this, you can use the Random.new() function:

local RandomVideo = ('rbxassetid://%d'):format(Random.new():NextInteger(1, #Videos))

%d represents a digit, more information about format can be found here:

VideoFrame = script.Parent

local Videos = {5608327482, 5608297917, 5608359401, 5608304953, 5608368298}
VideoFrame.Video = "rbxassetid://".. tostring(Videos[math.random(1,#Videos)])

When I run that code, The video gets broken (Paused) And dosen’t play. Same with @wf_sh idea.

Also, Sometimes it dosent appear too.

References:
Capture

Have you tried

VideoFrame = script.Parent

local Videos = {5608327482, 5608297917, 5608359401, 5608304953, 5608368298}
VideoFrame.Video = "rbxassetid://".. tostring(Videos[math.random(1,#Videos)])
VideoFrame:Play()

EDIT: I have tested this and this should work!

(The last code you see picks a random video, and it makes sure it is different to the last one.)

Random, different video every 3 seconds;

VideoFrame = script.Parent

local last = ""
local Videos = {5608327482, 5608297917, 5608359401, 5608304953, 5608368298}

local function change()
	local rand = "rbxassetid://".. tostring(Videos[math.random(1,#Videos)])
	if rand == last then
		change()
		return
	end
	VideoFrame.Video = rand
	VideoFrame:Play()
	last = rand
end

while wait(3) do
	change()
end
2 Likes