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

Why is my music (In StarterGui) not playing?

I am making a game that when you press a button a series of lanterns are released into the air followed by various effects.

Part of this is stopping the already playing music, and playing a new song. But when the button pressed (in-game) the music does not play and the lanterns are not released. Yet when in studio it works perfectly fine.

FE is NOT on.

Here is my code:

script.Parent.ClickDetector.MouseClick:connect(function()
	local la = game.Workspace.Lanterns
	local lag = la:GetChildren()
	for _,v in pairs(game.Players:GetChildren()) do
		v.PlayerGui.LIGHT:Play()
		v.PlayerGui.Nature:Stop()
		v.PlayerGui.Play.Disabled = true
		script.Parent.ClickDetector:Destroy()
		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
							wait(5)
							at:Destroy()
							wait(37)
							game.Workspace.Atmosphere.ParticleEmitter.Enabled = false
							wait(10)
							game.Lighting.SunRays.Intensity = 0.2
						end
					end
				end
			end)
		end
		wait(100)
		for _,v in pairs (lag) do
			v:Destroy()
		end
	end	
end)

Please help!

5 comments

0

Sound:Play(). c:

0

Does it really play in starterGui? ,I thought it only plays on PlayerGui

0

@Thee, Notice line 5, im trying to get it to play there. @roblor, It doesn't play in starterGui that's why im trying to make it play in playerGui (lines 5-7)

0

lol I was jk man. :P What's Play? (Line 7)

0

It's a script that makes nature play

1 answer

Looking at this script it would seem reasonable to separate the loop for players and the one for the lanterns.

script.Parent.ClickDetector.MouseClick:connect(function()
    local la = game.Workspace.Lanterns
    local lag = la:GetChildren()
    for _,v in pairs(game.Players:GetChildren()) do
        v.PlayerGui.LIGHT:Play()
        v.PlayerGui.Nature:Stop()
        v.PlayerGui.Play.Disabled = true
        script.Parent.ClickDetector:Destroy()
    end 
	 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
                            wait(5)
                            at:Destroy()
                            wait(37)
                            game.Workspace.Atmosphere.ParticleEmitter.Enabled = false
                            wait(10)
                            game.Lighting.SunRays.Intensity = 0.2
                        end
                    end
                end
            end)
        end
        wait(100)
        for _,v in pairs (lag) do
            v:Destroy()
        end
end)

Now it runs like this, for loop for the players, for loop for the lanterns, wait 100, then destroy

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