Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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
0
This worked now just gotta find the other problem with the image label Sergiomontani10 236 — 6y
Ad
Log in to vote
0
Answered by
RAYAN1565 691 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
I did in another part of the script Sergiomontani10 236 — 6y
0
Then the script should work unless you haven't correctly written line 8 to do what you wanted it to do. RAYAN1565 691 — 6y
Log in to vote
0
Answered by 6 years ago

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

Answer this question