What I am trying to achieve is, when someone joins there will be a sound inside their character inside workspace this is what i have done so far.But it doesn't work,I don't get anything from the output
01 | local PlayerService = game:GetService( "Players" ) |
02 | local PlayerPerson = PlayerService:GetPlayerFromCharacter() |
03 | local PlayerName = PlayerService.LocalPlayer.Name |
04 |
05 |
06 |
07 | function MusicNeeded() |
08 | print ( "Music is being added to " ..PlayerName.. "!" ) |
09 | wait( 3 ) |
10 | local MusicBeingAdded = Instance.new( "Sound" ) |
11 | MusicBeingAdded.Parent = PlayerPerson |
12 | end |
13 |
14 | PlayerService.PlayerAdded:Connect(MusicNeeded) |
``
Why not simply use the "player" paramater from the PlayerAdded
event, i'm not sure about what's wrong with your script though. Try this out and see if it works.
1 | function MusicNeeded(plr) |
2 | print ( "Music is being added to " ..plr.Name.. "!" ) |
3 | wait( 3 ) |
4 | local MusicBeingAdded = Instance.new( "Sound" ) |
5 | MusicBeingAdded.Parent = plr |
6 | end |
7 |
8 | PlayerService.PlayerAdded:Connect(MusicNeeded) |
Also putting it the player is kind of useless, since it will not act as a 3D object. So you may wanna put it inside the character
1 | function MusicNeeded(plr) |
2 | print ( "Music is being added to " ..plr.Name.. "!" ) |
3 | wait( 3 ) |
4 | local MusicBeingAdded = Instance.new( "Sound" ) |
5 | MusicBeingAdded.Parent = plr.Character |
6 | end |
7 |
8 | PlayerService.PlayerAdded:Connect(MusicNeeded) |
Why are you putting the sound inside of the player in Players rather than putting it into the character?
1 | game.Players.PlayerAdded:Connect( function (player) -- When a player joins |
2 | player.CharacterAdded:Connect( function (char)) -- When the character loads |
3 | local sound = Instance.new( "Sound" , char) -- Create the sound |
4 | end ) |
5 | end ) |