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

ReplicatedFirst.GameManager:11: bad argument #1 to 'random' (number expected, got table)?

I want a random sound but the Output get me this error

ReplicatedFirst.GameManager:11: bad argument #1 to 'random' (number expected, got table)

local GameManager = {
	DeathSounds = {
		131138839,
		131138845,
		131138854,	
	},
}

function zombieDeathSong(z)
	local sound = Instance.new('Sound', z)
	sound.SoundId = 'rbxassetid://'.. math.random(GameManager.DeathSounds)
	sound:Play()
end

2 comments

1

GameManager.DeathSounds[math.random(1, 3)]?

0

The error explains itself

1 answer

✓ Accepted answer

You're returning a table, as says kingdom5. To get a random thing inside a table, you do:

sound.SoundId = 'rbxassetid://'..GameManager.DeathSounds[math.random(1,#GameManager.DeathSounds)]

How this works: To access a certain thing inside a table, you do table[number] to access, for example, GameManager.DeathSounds[1] returns 131138839.

1 comment

0

Thanks:))

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