math.randomseed(tick()) -- makes sure when you constantly replay the game, their will be a different sound local Zombie = -- your zombie's head... if Zombie == nil then local a = -- Song ID local b = -- Song ID local c = -- Song ID local d = -- Song ID local e = -- Song ID local ZombieVoice = Instance.new("Sound", Zombie) ZombieVoice.SoundId = math.random(a,b,c,d,e) end
Put this inside of the zombie model. Your problem was Zombie
wasn't defined, and line 3 was used incorrectly. Please read through the wiki to learn more about scripting.
local head = script.Parent:WaitForChild("Head") local hum = script.Parent:WaitForChild("Zombie") --Name of humanoid (ex: Humanoid, Zombie, Alien, etc.) local sound = Instance.new("Sound"); sound.Parent = head; sound.Name = "Death" local deathSounds = { "rbxassetid://970780552", --These are examples of sounds. Put your own death sounds here. "rbxassetid://880612615" } hum.Died:Connect(function() --when zombie/humanoid dies sound.SoundId = deathSounds[math.random(1, #deathSounds)] --Selects random sound ID from table sound:Play() --play sound end)
If this helped you, please accept my answer. Thanks!
As you can see I removed the math.randomseed(tick()) line You didn't add commas after every line of each index and You didn't even play it Here is something, Get a folder and put in the sounds And then in the properties put the sound ID you want Btw I think you mean whenever the Zombie dies it plays the sound, I think thats what you want
local Zombie = workspace.Zombie if Zombie ~= nil then local sounds = { --Death Sounds-- workspace.Folder.Sound1, workspace.Folder.Sound2, workspace.Folder.Sound3, workspace.Folder.Sound4, workspace.Folder.Sound5, } local moan = { --Moan sounds-- workspace.Folder.Sound6, workspace.Folder.Sound7, workspace.Folder.Sound8, workspace.Folder.Sound9 } while Zombie.Humanoid.Health > 0 and wait() do for i,_ in pairs(moan) do moan[1,i]:Play() wait(5) end end Zombie.Humanoid.Died:Connect(function() for amount,_ in pairs(sounds) do sounds[math.random(1,amount)]:Play() end else print("Zombie is nil and cannot play sound!") end end)
Hopefully this helped!