Sound Plays When You Spawn In

  1. What do you want to achieve?
    Make a sound effect play when the player loads in & make the sound play if the player respawns

I’ve been digging through the devforum and Youtube but I’ve found nothing on how to make it work.

2 Likes

   Players = game:GetService("Players")

   Players.PlayerAdded:Connect(function(player)
              player.CharacterAdded:Connect(function()) -- each time char is added
              local sound = player.Sound
        sound:Play()
    end)
 end)

Make sure you parent whatever sound you want to play to the player, try parenting a local script to the sound in StarterPlayerScripts and using the local script to parent the sound to script.Parent.Parent, as that would be the Player logically.
1 Like

You’d probably wanna connect to CharacterAdded, which when it fires you play the audio.
Alternatively, you can connect to CharacterAppearanceLoaded to ensure the character is actually in Workspace, see this for the reasoning.
The code would look something like this:

local Players = game:GetService("Players")
local Client = Players.LocalPlayer
local Sound = ... -- Path to the sound

local function OnCharacterAppearanceLoaded(Character)
	Sound:Play()
end
if Client.Character then
	OnCharacterAppearanceLoaded(Client.Character)
end
Client.CharacterAppearanceLoaded:Connect(OnCharacterAppearanceLoaded)
6 Likes

10 posts were split to a new topic: Sound Plays When You Spawn In (Private Discussion)

The script works fine!
Sound plays as soon as I load in and when I spawn in.

2 Likes

8 posts were split to a new topic: Sound Plays When You Spawn In (Private Discussion 2)

A very simple thing you could do to achieve what you’re describing, is to set the sound’s Playing property to true by clicking the check box in studio as shown below and have it parented to a local instance such as StarterGui for example.

image

This will make the sound play as soon as you spawn in and requires absolutely no scripting and can be done by anyone whether you build, script, animate or whatnot. :slight_smile:

3 Likes

CharacterApperanceLoaded doesn’t ensure that the character is in the workspace because it fires before the character is even constructed. If you want to properly ensure that the character has spawned in (which isn’t even necessary for this problem), refer to RbxCharacterSounds:

Post #4, by the way, is unnecessary and I’m not sure why it’s marked as the solution. It doesn’t resolve the problem nor is it appropriate for the Developer Forums: this whole nonsense argument isn’t. There are other ways to resolve problems in others’ code and suggest improvements. Let’s not act in bad faith towards each other. Resolve problems in private messages rather than being inflammatory on a public thread, please.

@MediaMoIecule Please mark post #3 as the solution because it actually solves your problem.

3 Likes

It was marked as post#3 not sure why it got changed