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

Play audio on spawn?

Asked by 7 years ago

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.

0
You could use CharacterAdded, which will fire when the player spawns theCJarmy7 1293 — 7y
0
If someone helped you, please accept their answer. This helps us a lot! User#11440 120 — 7y

2 answers

Log in to vote
0
Answered by
iFlusters 355 Moderation Voter
7 years ago

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()
0
I morphed your answer a little bit. This would work though, but only once. Maybe that's what he wants idk. User#11440 120 — 7y
0
I'll try it out and let you guys know how it worked. NoobDeveloper 0 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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!

0
Thanks exactly what I needed NoobDeveloper 0 — 7y

Answer this question