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)
