|
| 11 May 2015 06:24 PM |
Hello fellow ROBLOXians, I am trying to make a script where a sound is LOCALLY played for 20 seconds when the player enters the game. I have finished most of the script, but I'm trying to find out how I can have the sound play only on the entering player's device. This is my script so far:
sound=script.Sound
function enter() sound:Play() wait(20) sound:Stop() end
game.Players.PlayerAdded:connect(enter)
What should I add/change/remove to make the sound in my script play LOCALLY only?
Thank you for helping me. Pikachu84639 |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 06:26 PM |
local sound = script.Sound -- local variable, faster
game.Players.PlayerAdded:connect(function(p) -- more efficient that way local soundClone = sound:Clone() soundClone.Parent = p.PlayerGui soundClone:Play() soundClone:Stop() soundClone:Destroy() end) -- add a ) because we did it on 1 line |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 06:33 PM |
You parented it in the playergui, if the player dies, no more sound.
Parent it in the player instead. |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 06:33 PM |
that was @thenewchicken btw.
|
|
|
| Report Abuse |
|
|
|
| 11 May 2015 06:52 PM |
| Thank you for that. I'm trying to make the sound play for only the first 20 seconds after the player joins the game. Can you please add that to the script? |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 06:53 PM |
I fixed his code and made it play for 20 seconds.
By fixed, it doesn't disappear when you die now.
local sound = script.Sound -- local variable, faster
game.Players.PlayerAdded:connect(function(p) -- more efficient that way local soundClone = sound:Clone() soundClone.Parent = p soundClone:Play() wait(20) soundClone:Stop() soundClone:Destroy() end) -- add |
|
|
| Report Abuse |
|
|
|
| 11 May 2015 06:59 PM |
| I already tried adding wait(20), but it wouldn't do anything. The sound would just continue playing until its real end. |
|
|
| Report Abuse |
|
|
|
| 15 May 2015 08:06 PM |
I already tried adding wait(20), but it wouldn't do anything. The sound would just continue playing until its real end.
So, does somebody have an answer? |
|
|
| Report Abuse |
|
|