Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
HaveASip 494 Moderation Voter
5 years ago

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)
0
Second parameter to the Instance.new() is deprecated, you should use OpenSound.Parent = workspace instead. AswormeDorijan111 531 — 5y
0
thanks so much i don't understand your script but thanks :P FrostyDevy 0 — 5y
0
@ AswormeDorijan111 I already seted the parent of sound - ("Sound" - name of variable, workspace --- parent of the sound) Instance.new(stringval, instance parent)  HaveASip 494 — 5y
0
yes but HaveASip, the parent parameter of Instance.new() is decaperated, it makes a difference look at this: https://gyazo.com/3cc3fb697653a893156d40282f66cfca User#23365 30 — 5y
Ad

Answer this question