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

random sound player not working? (reposted and solved)

Asked by 6 years ago
Edited 6 years ago

ok so i did repost the question because i dont think it was viewed that much, and i really need help to fix that script up.

repost:as you might have known by the title, i have made a script that plays a random sound inside a folder called MusicLobby, it was working fine back then, but now it doesnt work anymore and i did not change it. Well...it DOES work in STUDIO but not INGAME, and that makes me really confused...anyways here is the script that i made.

local trackslobby=workspace.MusicLobby:GetChildren()
local chooselobby=math.random(1,#trackslobby)
local trackl=trackslobby[chooselobby]
trackl:Play()

oh and also this script itself is in ServerScriptService, this is not actually the ENTIRE script, but i figured out that this specific part is the one that is breaking the script, hope you guys understand.

edit: i actually figured out what was the problem, it was not the script, i found out that there are alot of scripts called "vaccine" inside everything in my place, im figuring out what happened, anyways thanks for helping.

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

At the top of the script, try adding the line:

math.randomseed(tick())

The randomised number chosen from math.random is based off of the last random number chosen. If you set the seed to tick(), it sets the first number to a different one every time the game starts. So from then on, every random number you generate will vary each time you play.

If the randomisation isn’t the problem, the error may be somewhere else in your script.

Ad

Answer this question