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

Is there something wrong with this?

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)

1 comment

2

local s = Instance.new("Sound", newplayer) or s.Parent = newPlayer

1 answer

✓ Accepted answer

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)

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