Hey.
The second you read that title you might be thinking “this has been asked many times” because “infinite yield possible” is just a very regular warning that everyone gets.
The thing is that I couldn’t find a post related to my issue, so uh.
Basically this part of my (ModuleScript) would take a value from a folder in ReplicatedStorage and continue the thread:
EquationRemote.OnServerEvent:Connect(function(player)
local playerAnswer = ReplicatedStorage.PlayerAnswers:WaitForChild(player.Name)
if playerAnswer.Value == solution then
EquationRemote:FireClient(player)
playerAnswer:Destroy()
end
end)
The StringValue defined above is created using Instance.new() on a LocalScript:
answerInput.FocusLost:Connect(function(enterPressed, inputThatCausedFocusLoss)
if enterPressed == true and answerInput ~= "" then
print("Player submitted an answer.")
local playerAnswers = ReplicatedStorage.PlayerAnswers
local playerAnswer = Instance.new("StringValue")
playerAnswer.Parent = playerAnswers
playerAnswer.Name = Players.LocalPlayer.Name
EquationRemote:FireServer(playerAnswered, playerAnswer)
else return
end
end)
Maybe I’m not smart enough to see why this happens…
Thats the issue here…
The string value is not replicated to the server and so, you are waiting forever to find that string value.
A solution would be creating that value on server instead.
Like @EgizianoEG says above, this is because its a local script creating the StringValue instance - which is only visible to the local client - not server.
However, you could simplify this entirely by just including two parameters on the EquationRemote.OnServerEvent.
--you're already Firing this remote with the paramters 'playerAnswered' and 'playerAnswer', so make use of them.
EquationRemote.OnServerEvent:Connect(function(player,playerAnswered, playerAnswer)
if playerAnswer.Value == solution then
EquationRemote:FireClient(player)
end
end)
Switched the method for the question as well (it was using a stringvalue too), however, I now get another error, being related to the wrong parameters(?)
if sendAll and isGameRunning then
for _, player in pairs(Players:GetPlayers()) do
if table.find(inGamePlayers, player) ~= nil then
generateRandomEquation()
EquationRemote:FireClient(player, equation) -- equation seems to be nil
end
end
sendAll = false -- a boolean im using to allow the server to send a parameter to all players being it the first time
end
the function i’m using:
local function generateRandomEquation() --- create a random equation
-- a bunch of stuff here. equation is a string, maybe that's the issue? not sure how return works.
return equation
end