I'm making a menu with a textbox, where it modifies the volume of music played by a player, and a separate one for sound effects. I know what might be wrong, I just don't know how to fix it. Here is the script:
--variables local DarkModeButton = script.Parent.DarkModeButton local SettingsMenuFrame = script.Parent local BlueModeButton = script.Parent.BlueModeButton local LightModeButton = script.Parent.LightModeButton local CloseButton = script.Parent.CloseSettingsButton local SoundEffect = script.Parent.Parent.Sounds local UserInputService = game:GetService("UserInputService") local VolumeBox = script.Parent.MusicVolumeBox local Music = game.ReplicatedStorage.Music --functions VolumeBox:GetPropertyChangedSignal("Text"):Connect(function() if VolumeBox.Text == "0" then--set value to zero. I tried it and it doesn't work. I also tried the enum.keycode thing but it doesn't work either for i,v in pairs(Music:GetChildren()) do if v.ClassName == "Sound" then Music:GetChildren().Volume = 0 end end) DarkModeButton.MouseButton1Click:Connect(function() SettingsMenuFrame.BackgroundColor3 = Color3.new(0, 0, 0) for i,v in pairs(script.Parent:GetChildren()) do if v.ClassName == "TextButton" or "TextLabel" then Color3.new(1,1,1) end end end) LightModeButton.MouseButton1Click:Connect(function() SettingsMenuFrame.BackgroundColor3 = Color3.new(1,1,1) for i,v in pairs(script.Parent:GetChildren()) do if v.ClassName == "TextButton" or "TextLabel" then Color3.new(0,0,0) end end end) BlueModeButton.MouseButton1Click:Connect(function() SettingsMenuFrame.BackgroundColor3 = Color3.new(0,0,1) for i,v in pairs(script.Parent:GetChildren()) do if v.ClassName == "TextButton" or "TextLabel" then Color3.new(0,0,0) end end end) CloseButton.MouseButton1Click:Connect(function() SettingsMenuFrame:TweenPosition( UDim2.new(0.25,0,-4,0), "In", "Linear", 1, true ) end) for i,v in pairs(script.Parent:GetChildren()) do if v.ClassName == "TextButton" then v.MouseEnter:Connect(function() SoundEffect.HoverSound:Play() end) end end for i,v in pairs(script.Parent:GetChildren()) do if v.ClassName == "TextButton" then v.MouseButton1Click:Connect(function() SoundEffect.Click:Play() end) end end UserInputService.InputBegan:Connect(function(Input, gameProccessedEvent) if Input.UserInputType == Enum.UserInputType.Keyboard then if Input.KeyCode == Enum.KeyCode.S then SettingsMenuFrame:TweenPosition( UDim2.new(0.25,0,0.274,0), "Out", "Linear", 1, true ) end end end)
idk how to include screenshots pls help thanks
On this line...
Music:GetChildren().Volume = 0
You're really checking to see if there is a child named Volume, and set that Volume to 0. You see, GetChildren()
returns a table of Instances that are parented to the Instance the method is called from. Your script is probably erroring out when it tries to do this line of code.
What you can do is check if the music is currently playing by looping through GetChildren()
and inspecting the audio's Volume property, checking if the Volume is not 0 while using IsPlaying
.
IsPlaying
coincides with IsPaused
and its use is something of this nature, compared to IsPaused
:
local sound = script.Parent:FindFirstChildWhichIsA("Sound") sound:Play() -- Going to wait a set amount of time wait(sound.TimeLength / 4) -- Now manipulate the status of the sound if sound.IsPlaying then -- IsPlaying is read-only sound:Pause() -- Keeps the TimePosition; Stop() resets the TimePosition wait(sound.TimeLength / 8) if sound.IsPaused then -- Also read-only sound:Resume() -- Continue playing the sound from the saved TimePosition end end