'infinite yield possible on 'Players.shaz:WaitForChild("Values")' im trying to make it so when the player claims the booth it turns bool value to true

local claim = script.Parent.Parent.Parent.Parent.StandMesh.Claim

This will trigger the Proximty Prompt.

claim.Triggered:Connect(function(player)
local screengui = player.PlayerGui:WaitForChild('Popups')
local popup = player.PlayerGui:WaitForChild('Popups').ClaimedBooth
local bool = player:WaitForChild('Values').Claimed


Solution 1:[1]

"Infinite yield possible" is a warning. It lets you know that your code is unsafe, and that when this code executed, the Values object didn't exist (or was spelled incorrectly) for more than 5 seconds, and player:WaitForChild('Values') could not resolve to an object.

The documentation for Instance:WaitForChild() has this to say :

Notes

  • If a call to this function exceeds 5 seconds without returning, and no timeOut parameter has been specified, a warning will be printed to the output that the thread may yield indefinitely; this warning takes the form Infinite yield possible on 'X:WaitForChild("Y")', where X is the parent name and Y is the child object name.
  • This function does not yield if a child with the given name exists when the call is made.
  • This function is less efficient than Instance:FindFirstChild or the dot operator. Therefore, it should only be used when the developer is not sure if the object has replicated to the client. Generally this is only the first time the object is accessed

You can remove this warning by adding a timeout as a second argument, but you'll need to account for the fact that it's possible that the object isn't found :

local timeout = 2 -- seconds
local values = player:WaitForChild('Values', timeout)
if values then
    local boolVal = values.Claimed
    print("Claimed = ", boolVal.Value)
    -- mark it as claimed
    boolVal.Value = true
else
    warn("Could not find 'Values' BoolValue")
end

Alternatively, if you know that Values will exist at the time this code will execute, you can simply access it with the dot operator or with the FindFirstChild() function. But this will throw an "Attempt to index nil" error if Values doesn't exist.

local boolVal = player:FindFirstChild('Values').Claimed
-- or
local boolVal = player.Values.Claimed

-- mark it as claimed
boolVal.Value = true

When you see this warning, you should double check the spelling on the name of the object, as well as the timing of when the script executes to make sure that the object actually exists.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1