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

How to make this randomly pick a id?

Asked by 9 years ago

Can someone tell me how to make this script randomly pick a Id from the ValidIds table and change the SoundId to that?

local ValidIds = {"206068135","180477573"}

while wait(3) do
    script.Parent:Stop()
    for i,v in pairs(ValidIds) do
        script.Parent.SoundId = "rbxassetid://"..v
        script.Parent:Play()
    end
end

2 answers

Log in to vote
0
Answered by 9 years ago

Compliments of Validark, here is the application

local ValidIds = {"206068135","180477573"}

while wait(3) do
    script.Parent:Stop()
local randomSound = math.random(1, #ValidIds) -- Pick a number between 1 and the number of ValidIds

randomSound = ValidIds[randomSound] -- Find the selected value in the table
        script.Parent.SoundId = "rbxassetid://"..randomsound
        script.Parent:Play()
end
Ad
Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

Use math.random. More information on that here.

local randomSound = math.random(1, #ValidIds) -- Pick a number between 1 and the number of ValidIds

randomSound = ValidIds[randomSound] -- Find the selected value in the table
0
Can you give me a example of how I'd use it in my script? ISellCows 2 — 9y

Answer this question