Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't this math.Random script work properly?

Title says it all, its suppost to choose a Image from the list but doesnt do anything, not even a error. The image doesnt come up at all but it prints. Anything wrong with my code?

function RunVideo()
	local IsPlaying = false
	while wait(0.5) do
		if IsPlaying == false then
			local ImagesForVideo = "2169077935","2169077935","2169077935"
			local ImageValue = math.random(1,#ImagesForVideo)
			local TextInsertToImage = "rbxassetid://"..ImageValue
			script.Parent.BackRoundImageVideo.Image = ImageValue
			print("Working")
		end
	end
end

3 answers

✓ Accepted answer

First, the local ImagesForVideo needs to be a table. Next, you're gonna want to index the table and replace it as your own.

function RunVideo()
    local IsPlaying = false
    while wait(0.5) do
        if IsPlaying == false then
            local ImagesForVideo = {"2169077935","2169077935","2169077935"}
            local ImageValue = ImagesForVideo[math.random(1,#ImagesForVideo)]
            local TextInsertToImage = "rbxassetid://"..ImageValue
            script.Parent.BackRoundImageVideo.Image = ImageValue
            print("Working")
        end
    end
end

1 comment

0

This worked now just gotta find the other problem with the image label

Simply, you forgot to add RunVideo() at the end of the script, which would execute that whole function you've written. It won't run unless you state the function at the end.

All I did was add that:

function RunVideo()
    local IsPlaying = false
    while wait(0.5) do
        if IsPlaying == false then
            local ImagesForVideo = {"2169077935","2169077935","2169077935"} --always put brackets around a table of values
            local ImageValue = ImagesForVideo[math.random(1,#ImagesForVideo)] --need to do this to pull a value from the table
            local TextInsertToImage = "rbxassetid://"..ImageValue
            script.Parent.BackRoundImageVideo.Image = ImageValue
            print("Working")
        end
    end
end

RunVideo() --this is important

Try it now.

2 comments

0

I did in another part of the script

0

Then the script should work unless you haven't correctly written line 8 to do what you wanted it to do.

I barely found out that you cannot change the image in a localscript. Owell just ganna stick to the older one

This discussion is preserved as it was. New answers, comments, and votes are closed.