Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Infinite Yield Possible, No Clue why?

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?

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you, this worked, but then I get a "Radio is not a valid member of Player" error. I have a feeling I know what this is from but I don't know how to get the players character in Workspace. :(

0

Nevermind got it working!!! Thank you so much, have been trying to figure this out for days. :D

This discussion is preserved as it was. New answers, comments, and votes are closed.