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

Can i make NPC make a short sound everytime they spawn?

Asked by 4 years ago
Edited 4 years ago

i want to make a game where you defend something and npc's are spawning every minute.

2 answers

Log in to vote
0
Answered by 4 years ago

in the same "function()" do Play:sound. aka

local sound = "Your sound"

function()
    sound:Play()
end

Here is a good article:https://developer.roblox.com/en-us/api-reference/function/Sound/Play

Ad
Log in to vote
0
Answered by
pingsock 111
4 years ago
Edited 4 years ago
-- Where the NPC is supposed to respawn, you create a sound like this
-- I usually use functions so I'll drop my own function which I personally recommend.
local Sound = Instance.new("Sound",CharacterPath)
Sound.Volume = .5
Sound.Looped = false
Sound:Play()
-- It's way easier to manage these properties with a function, try out this one for example.
function CreateSound(ID, PARENT, VOLUME, PITCH)
    local Sound = nil
    coroutine.resume(coroutine.create(function()
        Sound = Instance.new("Sound", PARENT)
        Sound.Volume = VOLUME
        Sound.Pitch = PITCH
        Sound.SoundId = "http://www.roblox.com/asset/?id="..ID
        swait()
        Sound:play()
        game:GetService("Debris"):AddItem(Sound, 10)
    end))
    return Sound
end
-- This ensures the sound doesn't play for too long.
-- If you are still struggling feel free to friend me, I'll always accept requests.

Answer this question