I am making a game where (once a button is pressed) a series of lanterns are released into the air.
Part of this is taking "LIGHT" which is an audio snipit inside "StarterGui" and making it play as the lanterns are floating up.
I think it has to do with how my script is NOT local, but the music needs to be played locally.
Here is my code:
**local light = game.StarterGui.LIGHT** script.Parent.ClickDetector.MouseClick:connect(function() script.Parent.Transparency = 1 local la = game.Workspace.Lanterns local lag = la:GetChildren() for _,v in pairs (lag) do spawn(function() if v.Name == "LanternAtt" then local attA = v:FindFirstChild("AttachmentA") if attA then local at = attA:FindFirstChild("Attachment") if at then **light:Play()** at:Destroy() end end end end) end wait(100) for _,v in pairs (lag) do v:Destroy() end end)
The reason this isn't working is because you are attempting to play a sound instance which is inside startergui, startergui is used to replicated its contents to the PlayerGui of the player. to fix this we need to navigate to the sound instance inside the player's PlayerGui. We can also use the argument that the mouseclick event gives to us to get to the sound.
script.Parent.ClickDetector.MouseClick:connect(function(plr)--MouseClick event gives us the player script.Parent.Transparency = 1 local la = game.Workspace.Lanterns local lag = la:GetChildren() for _,v in pairs (lag) do spawn(function() if v.Name == "LanternAtt" then local attA = v:FindFirstChild("AttachmentA") if attA then local at = attA:FindFirstChild("Attachment") if at then plr.PlayerGui.LIGHT:Play()--look at how I navigated to the player's PlayerGui at:Destroy() end end end end) end wait(100) for _,v in pairs (lag) do v:Destroy() end end)
It is because you don't make the music inside the player play, but inside StarterGui.
script.Parent.ClickDetector.MouseClick:connect(function(player) local light = player.PlayerGui.LIGHT script.Parent.Transparency = 1 local la = game.Workspace.Lanterns local lag = la:GetChildren() for _,v in pairs (lag) do spawn(function() if v.Name == "LanternAtt" then local attA = v:FindFirstChild("AttachmentA") if attA then local at = attA:FindFirstChild("Attachment") if at then light:Play() at:Destroy() end end end end) end wait(100) for _,v in pairs (lag) do v:Destroy() end end)
Feel free to accept this answer if it helped you.