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

I'm not sure why this music script won't work properly?

Asked by
Txeer 46
4 years ago

I have a GUI that can play music. I set up a script that should set a bool value to false and prevent more audio from being added, instead I get this error: "Something unexpectedly tried to set the parent of Sound to NULL while trying to set the parent of Sound. Current parent is Workspace." Any ideas?

Script that updates the BoolValue:

game.Workspace.ChildAdded:Connect(function(ch)
    if ch.Name == "Sound" then

        game:GetService("ReplicatedStorage").canFire.Value = false

        ch.Changed:Connect(function()
            if ch.IsPlaying == false then
                game:GetService("ReplicatedStorage").canFire.Value = true
                ch:Destroy()
            end
        end)
    end
end)

FireServer script that adds the music:

local storage = game:GetService("ReplicatedStorage")
local events = storage:WaitForChild("RemoteEvents")


script.Parent.MouseButton1Click:Connect(function()

    local canFire = storage:WaitForChild("canFire")

    if canFire.Value == true then

    events.PlayMusic:FireServer(script.Parent.Parent.MusicID.Text)

    script.Parent.Parent.StopButton.Position = UDim2.new(0.3, 0, 0.94, 0)

    else

        script.Parent.Text = "An audio is already playing!"

        wait(3)

        script.Parent.Text = "Play"

    end
end)

Answer this question