- 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.
I’ve been digging through the devforum and Youtube but I’ve found nothing on how to make it work.
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)
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)
The script works fine!
Sound plays as soon as I load in and when I spawn in.
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.
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.
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.
It was marked as post#3 not sure why it got changed