Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Infinite yield automatically ends the script?

Asked by 5 years ago

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!

0
Try using pcall Leamir 3138 — 5y

1 answer

Log in to vote
4
Answered by 5 years ago
Edited 5 years ago

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

0
Thank you! This relay helped. ? OMG_Gaming404 73 — 5y
Ad

Answer this question