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

Play audio on spawn?

Help with this script I don't quite understand how to create a script for this.

A script that plays audio when someone spawns (Not Looped) and only you can hear it not other users.

And is the script a Local Script or a normal Script?,Where do I place it?(ex;Serverstorage,Replicated Storage.

2 comments

0

You could use CharacterAdded, which will fire when the player spawns

0

If someone helped you, please accept their answer. This helps us a lot!

2 answers

LocalScript in StarterGui

repeat wait() until game.Players.LocalPlayer.Character
local Player = game.Players.LocalPlayer

local Sound = Instance.new("Sound", Player.PlayerGui)
Sound.SounId = 0 --YOURSOUNDID
Sound.Volume = 1
--Sound.etc, change whatever settings.
Sound:Play()

2 comments

0

I morphed your answer a little bit. This would work though, but only once. Maybe that's what he wants idk.

0

I'll try it out and let you guys know how it worked.

It's normally best to use regular scripts for things like this.

Instead of using a LocalScript in StarterGui, use a regular script in ServerScriptService.

To get the Player, use a PlayerAdded Event. Like this,

game.Players.PlayerAdded:connect(function(plr)


end)

The above gives us the LocalPlayer, in a way.

Now to play a sound Locally, simply place the sound inside of the player. First, let's make the sound using Instance.new().

game.Players.PlayerAdded:connect(function(plr)
    local Sound = Instance.new("Sound",plr)--makes a sound and puts it in the player
end)

Now all we have to do is set the volume of the sound, the id of the sound, and play the sound! Here's what your script would look like,

--Regular script in ServerScriptService
game.Players.PlayerAdded:connect(function(plr)
    local Sound = Instance.new("Sound",plr)--makes a sound and puts it in the player
    Sound.SoundId = 0--Get your sound Id!
    Sound.Volume = 1--Sound Volume
    Sound:Play()
end)

This would be your script if you only wanted it to play once. However, if you want it to play whenever the player respawns, use a CharacterAdded Event. Like this,

--Regular script in ServerScriptService
game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)--Character Added
        local Sound = Instance.new("Sound",plr)
        Sound.SoundId = 0
        Sound.Volume = 1
        Sound:Play()
    end)
end)

That would make the sound play whenever the Character Respawns.

That's all.

Good Luck!

1 comment

0

Thanks exactly what I needed

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