I'm using two different models, one plays background music while the other blows things up, the problem I'm having is that they both play music. The one that blows up plays music when it is activated, and the other one always plays music. I'm trying to make the one that plays music stop playing when the one that blows up is activated. After some research, I found that the music is inside of a local script. The local script's parent is PlayerScripts, I'm not good at using "GetChildren()", so sorry if I used it incorrectly it, here is a snippet of my script:
for i,v in pairs(game.Players:GetChildren()) do -- Did I use this wrong? local Alarm = AssetsF:WaitForChild("Alarm") -- This stuff is what the bomb plays local Alarmb = AssetsF:WaitForChild("Alarm1") local Music = PlayerScripts:GetChildren() if not Alarm.IsPlaying then Alarm:Play() Alarmb:Play() Music.LocalBackgroundMusic:Destroy() -- This is the script that has the sound in it end end end
A big thanks if you can help me!
The script automatically runs as soon as a player joins your game. Meaning IsPlaying is only checked as soon as the script runs. What you should do is Parent the localscript under StarterPlayerScripts, that way it'll be saved under PlayerScripts for every player that joins. Then, you should use the event called Changed. Changed will fire every time a property is changed (hence changed). Eliminate the for loop and used the Changed event instead like this:
Alarm.Changed:Connect(function() -- Code here end)
I'm not very good at explaining things, but I hope this was sufficient enough.