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 5 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

local PlayerService = game:GetService("Players")
local PlayerPerson = PlayerService:GetPlayerFromCharacter()
local PlayerName = PlayerService.LocalPlayer.Name



function MusicNeeded()
    print("Music is being added to "..PlayerName.."!")
    wait(3)
    local MusicBeingAdded = Instance.new("Sound")
    MusicBeingAdded.Parent = PlayerPerson
end

PlayerService.PlayerAdded:Connect(MusicNeeded)

``

3 answers

Log in to vote
1
Answered by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 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.

function MusicNeeded(plr)
    print("Music is being added to "..plr.Name.."!")
    wait(3)
    local MusicBeingAdded = Instance.new("Sound")
    MusicBeingAdded.Parent = plr
end

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

function MusicNeeded(plr)
    print("Music is being added to "..plr.Name.."!")
    wait(3)
    local MusicBeingAdded = Instance.new("Sound")
    MusicBeingAdded.Parent = plr.Character
end

PlayerService.PlayerAdded:Connect(MusicNeeded)
0
lol its been 17 days but ty! starmaq 1290 — 5y
Ad
Log in to vote
2
Answered by 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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

game.Players.PlayerAdded:Connect(function(player) -- When a player joins
    player.CharacterAdded:Connect(function(char)) -- When the character loads
        local sound = Instance.new("Sound", char) -- Create the sound
    end)
end)

Answer this question