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

What's wrong in this script?

Asked by 8 years ago

Making a "The Infection" type game and I'm trying to make it so it plays a random audio everytime humans/zombies win. But when I try, the timer stops and nothing happens. What's wrong in this?

    function PickRandomFrom(tab)

    return tab[math.random(1,#tab)]

    end

    local id = PickRandomFrom(225032784,225032798,225032815)

    local WinMusic = Instance.new("Sound", Game.Workspace)

    WinMusic.SoundId = "http://www.roblox.com/asset?id=" ..id.. ""
    WinMusic:Play()
    wait(15)
    WinMusic:Remove()

1 answer

Log in to vote
1
Answered by 8 years ago

Your error here was with the table, if you want to declare a table you need to put this thing {}

Your code fix here:

local idsSound = {225032784, 225032798, 225032815}

function PickRandomFrom(sounds)
    local randomNumber = math.random(1, #sounds)

    return sounds[randomNumber]
end

local id = PickRandomFrom(idsSound)

local WinMusic = Instance.new("Sound", workspace)

WinMusic.SoundId = "http://www.roblox.com/asset?id=" ..id.. ""
WinMusic:Play()
wait(15)
WinMusic:Remove()
1
Works, thank you! ShadowsBeans 0 — 8y
0
You're welcome ! XToonLinkX123 580 — 8y
Ad

Answer this question