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

When a Zombie Dies Play's one of the sound id's?

Asked by 6 years ago
Edited 6 years ago
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

2 answers

Log in to vote
1
Answered by 6 years ago

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!

0
This is 100% correct. <3 IcyEvil 260 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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!

Answer this question