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

How do i insert a sound inside a player?

Asked by 6 years ago

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

01local PlayerService = game:GetService("Players")
02local PlayerPerson = PlayerService:GetPlayerFromCharacter()
03local PlayerName = PlayerService.LocalPlayer.Name
04 
05 
06 
07function MusicNeeded()
08    print("Music is being added to "..PlayerName.."!")
09    wait(3)
10    local MusicBeingAdded = Instance.new("Sound")
11    MusicBeingAdded.Parent = PlayerPerson
12end
13 
14PlayerService.PlayerAdded:Connect(MusicNeeded)

``

3 answers

Log in to vote
1
Answered by
starmaq 1290 Moderation Voter
6 years ago
Edited 6 years ago

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.

1function MusicNeeded(plr)
2    print("Music is being added to "..plr.Name.."!")
3    wait(3)
4    local MusicBeingAdded = Instance.new("Sound")
5    MusicBeingAdded.Parent = plr
6end
7 
8PlayerService.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

1function 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
6end
7 
8PlayerService.PlayerAdded:Connect(MusicNeeded)
0
lol its been 17 days but ty! starmaq 1290 — 6y
Ad
Log in to vote
2
Answered by 6 years ago

Sorry i was a noob at scripting here, i have fixed it :D

Log in to vote
1
Answered by 6 years ago

Why are you putting the sound inside of the player in Players rather than putting it into the character?

1game.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)
5end)

Answer this question