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

Infinite yield automatically ends the script?

Hello there! I have a LocalScript which waits for a Remote Function in Replicated Storage

I have the following code:

local Replicated_Storage = game:GetService("ReplicatedStorage")

Replicated_Storage:WaitForChild("SomeRemoteFunction").OnClientInvoke = function(GroupID, RankType)
	if RankType == 1 then -- Rank ID
		return LocalPlayer:GetRankInGroup(GroupID)
	elseif RankType == 2 then -- Role
		return LocalPlayer:GetRoleInGroup(GroupID)
	else -- Is In Group
		return LocalPlayer:IsInGroup(GroupID)
	end
end

-- CODE ISN'T EXECUTED AFTER THIS POINT

script.Parent.Welcome.Visible = true

The thing is, I want my code to continue running even if an Infinite yield possible event/error/warning occurs.

Any help would be appreciated!

1 comment

0

Try using pcall

1 answer

✓ Accepted answer

A simple solution would be to just move the code to the bottom of the script as it would the yield after all of the critical code has ran also note that Infinite yield possible is a warning.

-- critical code setup

--- code

-- setup events could yield

The second option would be to create a thread around that block allowing the code to run in the event that the child is not found.

Example using spawn

local Replicated_Storage = game:GetService("ReplicatedStorage")

spawn(function()
	Replicated_Storage:WaitForChild("SomeRemoteFunction").OnClientInvoke = function()
		-- code
	end
end)

-- other code

Lastly I should mention that WaitForChild has a second optional argument which is the time before returning nil.

Hope this helps

1 comment

0

Thank you! This relay helped. ?

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