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

What's wrong in this script?

Making a "The Infection" type game and I'm trying to make it so it plays a random audio everytime humans/zombies win. But when I try, the timer stops and nothing happens. What's wrong in this?

	function PickRandomFrom(tab)
		
	return tab[math.random(1,#tab)]

	end

	local id = PickRandomFrom(225032784,225032798,225032815)

	local WinMusic = Instance.new("Sound", Game.Workspace)

	WinMusic.SoundId = "http://www.roblox.com/asset?id=" ..id.. ""
	WinMusic:Play()
	wait(15)
	WinMusic:Remove()

1 answer

✓ Accepted answer

Your error here was with the table, if you want to declare a table you need to put this thing {}

Your code fix here:

local idsSound = {225032784, 225032798, 225032815}

function PickRandomFrom(sounds)
	local randomNumber = math.random(1, #sounds)
	
	return sounds[randomNumber]
end

local id = PickRandomFrom(idsSound)

local WinMusic = Instance.new("Sound", workspace)

WinMusic.SoundId = "http://www.roblox.com/asset?id=" ..id.. ""
WinMusic:Play()
wait(15)
WinMusic:Remove()

2 comments

1

Works, thank you!

0

You're welcome !

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