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

My script random.math is not working, not sure of the problem?

So this script is just, not working.

It appears to me its correct but I cant find any error.


while true do
	local songs = math.random(1,12)
if songs == 1 then
	script.Music:FindFirstChild("1Alone"):Play()
end
if songs == 2 then
	script.Music:FindFirstChild("2BuryAFriend"):Play()
end
if songs == 3 then
	script.Music:FindFirstChild("3FUN"):Play()
end
if songs == 4 then
	script.Music:FindFirstChild("4Happier"):Play()
end
if songs == 5 then
	script.Music:FindFirstChild("5HeartAndSoul"):Play()
end
if songs == 6 then
	script.Music:FindFirstChild("6Money"):Play()
end
if songs == 7 then
	script.Music:FindFirstChild("7MyBoy"):Play()
end
if songs == 8 then
	script.Music:FindFirstChild("8RainingTacos"):Play()
end
if songs == 9 then
	script.Music:FindFirstChild("9SpookyScarySkeletons"):Play()
end
if songs == 10 then
	script.Music:FindFirstChild("10ThankUNext"):Play()
end
if songs == 11 then
	script.Music:FindFirstChild("11Thunder"):Play()
end
if songs == 12 then
	script.Music:FindFirstChild("12WithoutMe"):Play()
end
print(math.random)
wait(20)

end

the script is inside the script service

Music is a folder inside the script

After FindFirstChild is an audio

Im trying to make random songs play

Im sure there are easier methods but I understand this one so please dont ask me to do an entirely different method oof.

At the end it says

print(math.random)

but then it prints something like this:

function: (random numbers and letters here)

I have no idea whats wrong

1 comment

0

because math.random is a function

1 answer

✓ Accepted answer

You're thinking way too hard. So we just use GetChildren() to make a table of the Music folder, then we use random to pick 1, then we play it. After 20 seconds it repeats. This should work, let me know if I messed anything up.

while true do
	local songlist = script.Music:GetChildren()
	local songs = math.random(1,#songlist)
	local songchosen = songlist[songs]
	songchosen:Play()
	wait(20)
	songchosen:Stop()
end

2 comments

0

or simply have all the music inside the script instead of having objects

0

u life savor thanks

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