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

Is there something wrong with this?

Asked by
thePyxi 179
10 years ago

Don't know how to put the Instance into the Player...

Someone help me?

function onPlayerEntered(newPlayer)
    -- I don't know how to put the Instance into the Player...  
    local s = Instance.new("Sound")
    s.Name = "Music"
print("1")  
    s.Volume = 1
    s.Looped = true
print("2")  
    s.SoundId = "rbxassetid://142896835"
    s.IsPaused = false
    s.IsPlaying = true
    print("3")
end

game.Players.ChildAdded:connect(onPlayerEntered)
2
local s = Instance.new("Sound", newplayer) or s.Parent = newPlayer Redbullusa 1580 — 10y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

There is a second argument for the Instance.new method, it returns the parent of the Instance. So in your script, to parent it to the player we'd go like..

local s = Instance.new("Sound",newPlayer)
--[[
We use the parameter from your function you're using for the PlayerAdded event
]]--

But I'm assuming that you want this sound to be heard, correct? Then you need to parent it to not the player, but the Player's PlayerGui.

local s = Instance.new("Sound",newPlayer.PlayerGui)

But also, you neglected to play the Sound in your script.. So your whole script should look like;

game.Players.PlayerAdded:connect(function(newPlayer)
    wait(1) --just for safety(;
    local s = Instance.new("Sound")
    s.Name = "Music"
    print("1")  
    s.Volume = 1
    s.Looped = true
    print("2")
    s.SoundId = "rbxassetid://142896835"
    s:Play() --We play the ausio with the 'Play' method.
    print("3")
end)
Ad

Answer this question