i want to make a game where you defend something and npc's are spawning every minute.
COMMUNITY QUESTION
Can i make NPC make a short sound everytime they spawn?
2 answers
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
-- 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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
