I’m trying to make a sound randomly play, here is a script the randomly changes the pitch, but how could I make it randomly play the sound?
while true do
wait()
script.Parent.PlaybackSpeed = math.random(70, 160)/100
end
I’m trying to make a sound randomly play, here is a script the randomly changes the pitch, but how could I make it randomly play the sound?
while true do
wait()
script.Parent.PlaybackSpeed = math.random(70, 160)/100
end
A simple way to wait a random period of time would be using wait(math.random(min,max))
in the loop.
You could also write while wait() do instead.
How could I print the wait() so I can see how long the sound took to play
You could create a variable that chooses a random number for the wait time. Then you can used that information and print it or use it in a wait. It would look something like this:
while true do
local randomNumber = math.random(min, max)
wait(randomNumber)
print(ramdomNumber)
end
Is there a way to do it without editing this script much?
while true do
wait()
script.Parent.Playing = wait(math.random(4,15))
print()
end
Well, yes…?
while true do local randomNumber = math.random(min, max) wait(randomNumber) script.Parent.Playing = wait(math.random(4,15)) print(randomNumber) end
If you have more sounds to play, you need to add them in a table
soundlist = {your instances}
after that you need to get instances of it by doing
local getchildren = script.Parent.Parent:GetChildren()
for _,v in pairs(getchildren) do
local findbytable = table.find(soundlist,v)
if findbytable ~= nil then
-- // do random chance
local chance = Random.new():NextNumber(0,100)
if chance < 25 then
v:Play()
break
end
end
end
(it’s kinda incomplete or was in rush, but try to finish it)