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

Making begining music, want it to stop when button pressed, stops automatically when joining game?

I am making a script that make music play when you enter the game... I want the script to make the music stop when you press the begin (gui button). But when i test the game the music stop 1.5 seconds after i join the "test" game.

Here is the script:(local script i put inside the gui button)

local OpenSound = Instance.new("Sound", game.Workspace)
local begin = script.Parent 

OpenSound.SoundId = "rbxassetid://1837482907"
wait(0.5)
OpenSound:Play()
wait(1) 


	  repeat
		wait(1) 
	if begin.MouseButton1Click:connect()  
		then OpenSound:Stop()
			else wait(1)
		end
		until OpenSound:Stop() == true

1 answer

You have many errors in your script. That errors on from 10 to 16 lines. You used repeat wrong

local OpenSound = Instance.new("Sound", workspace)
local BeginButton = script.Parent

OpenSound.SoundId = "rbxassetid://1837482907"
wait(.5)
OpenSound:Play()

BeginButton.MouseButton1Click:Connect(function()
	if OpenSound then
		wait()
		OpenSound:Stop()
	end
end)

4 comments

0

Second parameter to the Instance.new() is deprecated, you should use OpenSound.Parent = workspace instead.

0

thanks so much i don't understand your script but thanks :P

0

@ AswormeDorijan111 I already seted the parent of sound - ("Sound" - name of variable, workspace --- parent of the sound) Instance.new(stringval, instance parent) 

0

yes but HaveASip, the parent parameter of Instance.new() is decaperated, it makes a difference look at this: https://gyazo.com/3cc3fb697653a893156d40282f66cfca

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