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

Sound script choosing once?Describe

Hello, I have a script that chooses a random horn sound for the car, but it doesn't work. I only get one sound?? It doesn't even choose a sound anymore, it just picks a random sound only once,

local sounds = {200530606, 2606409476, 691472063, 3073594711, 3077820090, 1996722997, 2685453585, 1141737702, 547270621, 587945238, 132030515, 774652556, 972340421, 1951008488, 232030689}
local Rand = math.random(#sounds)

while wait(1) do
	script.Parent.SoundId = "http://www.roblox.com/asset/?id=" .. sounds[Rand]
end

1 answer

✓ Accepted answer

math.random() has 2 parameters, the minimum number and the maximum number. So just do, also put the rand variable inside the while loop.

local sounds = {200530606, 2606409476, 691472063, 3073594711, 3077820090, 1996722997, 2685453585, 1141737702, 547270621, 587945238, 132030515, 774652556, 972340421, 1951008488, 232030689}


while wait(1) do
    local Rand = math.random(1,#sounds)
    script.Parent.SoundId = "http://www.roblox.com/asset/?id="..tostring(sounds[Rand])
end

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