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

Sound plays when player joins a game [Easy fix?]

So i have this script that should play a sound when someone joins my game, but it doesn't work. Please help me out!

sound = Instance.new("Sound", game.StarterPlayer.StarterPlayerScripts)

sound.Id = "..." sound:Play()

(Also it should play only for you not for eveyone)

1 comment

0

If you want it to just play for you, you'd have to make the script local.

3 answers

Firstly, why would you put a sound inside StarterPlayerScripts which is intended for scripts for the player and Id isnt just three dots or its a placeholder for a ID. You could make this play locally by playing the Sound on a local script and parent the sound to StarterGui so it would play locally.

local player = game.Players.LocalPlayer
local sound = Instance.new("Sound")

sound.SoundId = "rbxassetid://"..--id here
sound.Parent = player.PlayerGui
sound:Play()

also this would have to be a local script since you can only access LocalPlayer on a LocalScript.

NOTE the parent parameter of Instance.new() is deprecated, just set the parent last.

10 comments

0

Nice

0

Man it didnt work

0

then you doing it wrong

0

I dont need it to play locally. Only so you can hear it once you join

0

use the PlayerAdded event

0

but you said you only wanted the sound to play for you not everyone

0

Quick sidenote - there is nothing wrong with having sounds inside of SPS - and they will run perfectly fine.

0

yes, but why would you even put it in there 

0

Just making the note. I've had IntValues in SPS before as very obscure solutions to problems. Rather than focusing on more pedantic issues it may prove more effective to focus on the actual question; however, with that being said. if OP really wanted a sound in SPS they should put it there manually rather than creating it from a script - which is bound to cause issues. This can be done by creating

0

Wow... did my reply just get cut off lol? I'm new to this site.

Create a sound with your desired ID inside of any client folder (SPS, StarterGui) - then just wait for its creation and play it once it is found.

local Sound = game.Players.LocalPlayer.PlayerGui:WaitForChild("Sound")
Sound:Play()

If you want it to just play for one person, you'd have to make a localscript and use "LocalPlayer". So, you'd have to do this:

game.Players.PlayerAdded(function()
    local Sound = Instance.new("Sound")
    Sound.Parent = game.Players.LocalPlayer.PlayerGui
    Sound.SoundId = Id here
    Sound:Play()
end)

Place the LocalScript inside of ServerScriptService as a LocalScript.

2 comments

0

Also, there are lots of ways on how to do this method. this is just a method using only one object.

0

didnt work

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