kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 11 Nov 2016 09:05 AM |
hi,
i have a toggle music mechanism in my game and it primarily works based on having a Sound instance inside a Player instance so it can be toggled for that player alone at will
the problem is, the system used to work perfectly
now it works perfectly in studio but in the actual game it either:
-does not play anything at all
-does this weird glitch where the sound instance skips a huge chunk of the song and then goes to the start after like 30 seconds
i have not modified anything in the script for the past 3 months aside from me making minor changes to try and fix it
can this be solved? |
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
| |
|
|
| 11 Nov 2016 03:56 PM |
| I read somewhere that if you put it in a Gui it will work the same but i have never done anything like this :/ |
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 11 Nov 2016 03:57 PM |
@enz
it does work inside a gui
the problem is i want the music playing to be consistent even when you die, which is why i put it in the Player instance and writing code for it to be as close as possible to "consistent" is a waste of time
|
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 04:06 PM |
| I done some testing(not much) in studio and when i checked the box 'PlayOnRemove' it worked after i died? |
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 11 Nov 2016 04:07 PM |
i do not want to use playonremove because the whole point is for it to NOT be removed when the player dies
|
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
| |
|
| |
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 12 Nov 2016 08:43 AM |
@forever
i don't think it's necessary, but all right
this is the portion of the main game's code that controls this
function queueSong(song, player) --syntax: Soundtable song, String player if player == "all" then for i,v in pairs(game.Players:GetPlayers()) do v:WaitForChild("ActiveSound"):Stop() v.ActiveSound.SoundId = song[3].SoundId end else local plrPlayer = game.Players:FindFirstChild(player) if plrPlayer == nil then return false end plrPlayer:WaitForChild("ActiveSound"):Stop() plrPlayer.ActiveSound.SoundId = song[3].SoundId end end
function playSong(player) wait(0.5) if player == "all" then for i,v in pairs(game.Players:GetPlayers()) do v:WaitForChild("ActiveSound"):Play() end else local player2 = game.Players:FindFirstChild(player) if player2 == nil then return false end wait(0.5) player2:WaitForChild("ActiveSound"):Play() end end
function stopSong(player) if player == "all" then for i,v in pairs(game.Players:GetPlayers()) do v:WaitForChild("ActiveSound"):Stop() end else local player2 = game.Players:FindFirstChild(player) if player2 == nil then return false end wait(0.5) player2:WaitForChild("ActiveSound"):Stop() end end
game.Players.PlayerAdded:connect(function(player) local sound = Instance.new("Sound", player) sound.Name = "ActiveSound" sound.Volume = 1 sound.Looped = true queueSong(selectedSong, player.Name) playSong(player.Name) end)
function isLobbySongPlaying() -- Due to Kandan's amazing coding skills and methods, this function had to be created in order for the music toggle feature to work. for i,v in pairs(lobbyMusicIDs) do if v == song3.Value then return true end end return false end
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Nov 2016 08:47 AM |
put the sound in backpack. try that
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Nov 2016 08:48 AM |
otherwise you will have to put the sound in workspace locally and play it from there
|
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 12 Nov 2016 08:50 AM |
"put the sound in backpack. try that"
but the whole point of the sound in the player instance is so that it plays smoothly even when you die (dying is frequent in my game)
the backpack is cleared when you respawn, no?
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Nov 2016 08:51 AM |
If i thought backpack was cleared when you spawn then I wouldn't have suggested it.
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Nov 2016 09:01 AM |
I lied. Place the sound is StarterPlayerScripts
|
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 12 Nov 2016 09:07 AM |
@time
how would i modify the code to work with the sound in the starterplayerscripts? where is it inserted in the player when someone joins?
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Nov 2016 09:08 AM |
local sound = player.PlayerScripts:WaitForChild('Sound')
|
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 12 Nov 2016 09:35 AM |
@time
i just implemented this. it has the same problem
there also appears to be an inconsistency between studio and the actual game
studio has the PlayerScripts in the player, while the game does not. (i ran a console command to print the contents of my player and PlayerScripts is not one of them)
|
|
|
| Report Abuse |
|
|
kings53
|
  |
| Joined: 17 Jul 2012 |
| Total Posts: 4375 |
|
|
| 12 Nov 2016 03:41 PM |
i have successfully implemented it and music works again
thank you so much for your support
|
|
|
| Report Abuse |
|
|