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

How to make this randomly pick a id?

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

✓ Accepted answer

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

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

1 comment

0

Can you give me a example of how I'd use it in my script?

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