So basically I'm making a Filtering Enabled radio thats a weld on the players back. The radio inserts in the the players Character, inside of the radio is a Gui that has the input, play song button etc. you insert the song id into an on-screen gui.
Here's the code in the Gui.
local remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes") local userInputService = game:GetService("UserInputService") local frame = script.Parent:WaitForChild("Frame") local player = script.Parent.Parent.Parent frame:WaitForChild("Play").MouseButton1Click:connect(function(frame, player) print("Playing song") remotes.PlaySong:InvokeServer() end) frame:WaitForChild("Stop").MouseButton1Click:connect(function() print("Stopping song") remotes.StopSong:InvokeServer() end)
And here is the code inside of the ServerScript which plays the song etc.
local remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes") sound = Instance.new("Sound") sound.Volume=1 sound.Pitch=1 sound.Name="" sound.Looped=true sound.PlayOnRemove=false local Format = "http://www.roblox.com/asset/?id=##ID##" remotes.PlaySong.OnServerInvoke = function(frame, player) local input = tonumber(frame:WaitForChild("Input").Text) if input then sound:Stop() sound.SoundId=Format:gsub("##ID##", tostring(input)) sound:Play() sound.EmitterSize = 0.5 sound.Parent = player.Radio end end
The issue I'm having is whenever I click play song I get Infinite yield possible on 'Players.gage7252002:WaitForChild("Input")
The script does not execute pas the if input then part. No clue why this is happening, can anyone help?
The reason this errors is because you're waiting for a child called 'Frame' in the client that invoked the remotefunction. The first parameter of a RemoteFunction handled on the server, and a RemoteEvent handled on the server is the client that invoked/fired the RemoteFunction/RemoteEvent.
Here's a fix for your scripts:
--Server Stuff remotes.PlaySong.OnServerInvoke = function(player, txt) local input = txt -- continue with the rest of the code end) --Client stuff -- You should also note that when a button is clicked, no arguments are passed, so we should have no parameters in MouseButton1Click frame:WaitForChild('Play').MouseButton1Click:Connect(function() remotes.PlaySong:InvokeServer(frame:WaitForChild('Input').Text) end)