Hello, I am making a Filtering Enabled compatible music player GUI for my game. The scripts work in Studio, but not in Game. I am using Remote Events to play the songs. Whenever I press the play button, the sound does not play.
There are no errors. If anyone can help me why it's not working, I would be thankful.
Local Script:
-- Objects local MusicGui = Instance.new("ScreenGui") local Base = Instance.new("Frame") local Enter = Instance.new("TextButton") local MusicID = Instance.new("TextBox") local GUILine = Instance.new("Frame") local no = Instance.new("Frame") local FE = Instance.new("TextLabel") local GUILine_2 = Instance.new("Frame") local no_2 = Instance.new("Frame") local Creditz = Instance.new("TextLabel") local remote = Instance.new("RemoteEvent") local sound = Instance.new("Sound") -- Properties script.Script.Parent = Base MusicGui.Name = "FE Play Music" MusicGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui") Base.Name = "Base" Base.Parent = MusicGui Base.Active = true Base.BackgroundColor3 = Color3.new(1, 1, 1) Base.BorderSizePixel = 0 Base.Draggable = true Base.Position = UDim2.new(0.334787179, 0, 0.324938855, 0) Base.Selectable = true Base.Size = UDim2.new(0, 496, 0, 249) remote.Name = "Remote" remote.Parent = Base sound.Parent = Base -- Properties Enter.Name = "Enter" Enter.Parent = Base Enter.BackgroundColor3 = Color3.new(0.0588235, 0.513726, 0.164706) Enter.BorderSizePixel = 0 Enter.Position = UDim2.new(0.33692233, 0, 0.624793768, 0) Enter.Size = UDim2.new(0, 144, 0, 50) Enter.Font = Enum.Font.Highway Enter.Text = "Execute" Enter.TextColor3 = Color3.new(0, 0, 0) Enter.TextSize = 25 Enter.MouseButton1Click:Connect(function() print("Executed") local player = game.Players.LocalPlayer.Name remote:FireServer(tonumber(MusicID.Text)) end) GUILine.Name = "GUI Line" GUILine.Parent = Base GUILine.BackgroundColor3 = Color3.new(0.0823529, 0.639216, 0.219608) GUILine.BorderSizePixel = 0 GUILine.Position = UDim2.new(-0.000363619998, 0, -0.00101011992, 0) GUILine.Selectable = true GUILine.Size = UDim2.new(0, 496, 0, 12) no.Name = "no" no.Parent = GUILine no.BackgroundColor3 = Color3.new(0.0901961, 0.780392, 0.239216) no.BorderSizePixel = 0 no.Position = UDim2.new(0, 0, 1, 0) no.Size = UDim2.new(0, 496, 0, 67) FE.Name = "FE" FE.Parent = GUILine FE.BackgroundColor3 = Color3.new(1, 1, 1) FE.BackgroundTransparency = 1 FE.Position = UDim2.new(0.258244455, 0, 0.00167793036, 0) FE.Size = UDim2.new(0, 240, 0, 86) FE.Font = Enum.Font.Highway FE.Text = "Filtering Enabled Music Player" FE.TextSize = 35 GUILine_2.Name = "GUI Line" GUILine_2.Parent = Base GUILine_2.BackgroundColor3 = Color3.new(0.0823529, 0.639216, 0.219608) GUILine_2.BorderSizePixel = 0 GUILine_2.Position = UDim2.new(-0.000363620929, 0, 0.960183144, 0) GUILine_2.Size = UDim2.new(0, 496, 0, 18) MusicID.Name = "MusicID" MusicID.Parent = Base MusicID.BackgroundColor3 = Color3.new(0.721569, 0.721569, 0.721569) MusicID.BackgroundTransparency = 0.25 MusicID.BorderSizePixel = 0 MusicID.Position = UDim2.new(0.0927419364, 0, 0.409354118, 0) MusicID.Size = UDim2.new(0, 403, 0, 50) MusicID.Font = Enum.Font.Highway MusicID.Text = "142376088" MusicID.TextColor3 = Color3.new(0, 0, 0) MusicID.TextSize = 28 MusicID.TextWrapped = true no_2.Name = "no" no_2.Parent = GUILine_2 no_2.BackgroundColor3 = Color3.new(0.0901961, 0.780392, 0.239216) no_2.BorderSizePixel = 0 no_2.Position = UDim2.new(0, 0, -1.43478262, 0) no_2.Size = UDim2.new(0, 496, 0, 33) Creditz.Name = "Creditz" Creditz.Parent = GUILine_2 Creditz.BackgroundColor3 = Color3.new(1, 1, 1) Creditz.BackgroundTransparency = 1 Creditz.BorderSizePixel = 0 Creditz.Position = UDim2.new(0.00806450844, 0, -1.91666675, 0) Creditz.Size = UDim2.new(0, 488, 0, 50) Creditz.Font = Enum.Font.Highway Creditz.Text = "Credit to BloxRoxe for the script." Creditz.TextSize = 20
Script inside Gui:
wait() local Remote = script.Parent:WaitForChild("Remote") local Sound = script.Parent:WaitForChild("Sound") function playSong(id) print(id) id = id or "" if Sound then Sound:Destroy() end Sound = Instance.new'Sound' Sound.Parent = game.Workspace Sound.Volume = 1 Sound.Looped = false Sound.PlayOnRemove = true Sound.SoundId = "http://www.roblox.com/asset/?id="..id Sound:Play() end function onRemote(player, id) playSong(id) end Remote.OnServerEvent:Connect(onRemote)
i'm no expert, but, i'll throw in my two cents;
i don't think the script should be in playergui. localscript is fine, though, a little bit of a mess.
edit the script so instead, it defines the sound in the function, and that the remote event comes from ReplicatedStorage;
local function playSong(id, sound)
and then change remote's base to ReplicatedStorage to properly function across servers in the local script;
remote.Parent = game:GetService("ReplicatedStorage")
hopefully that helped a bit, because i've certainly never heard of a remote event in a playergui.