Infinite Yield Problem

Hey, so I’m trying to script it so the script looks for a shirt on the player and if the character doesn’t have a shirt, it makes the id = 0 for the shirt from the viewmodel. Yet, for some reason, it doesn’t work when it doesn’t find the shirt. It works when it finds a shirt though. I’d really appreciate the help! :smile:

Code:

local foundShirt = Character:FindFirstChild(“Shirt”)
if not foundShirt then
viewModel.LeftArm.Shirt = 0
viewModel.RightArm.Shirt = 0
else if foundShirt then
viewModel.RightArm.Shirt.Texture = Character.Shirt.ShirtTemplate
viewModel.LeftArm.Shirt.Texture = Character.Shirt.ShirtTemplate
end
end

Try reording the if statements a bit:

local foundShirt = Character:FindFirstChild(“Shirt”)
if foundShirt then
   viewModel.RightArm.Shirt.Texture = Character.Shirt.ShirtTemplate
   viewModel.LeftArm.Shirt.Texture = Character.Shirt.ShirtTemplate
else
   viewModel.LeftArm.Shirt = 0
   viewModel.RightArm.Shirt = 0
end

An “Infinite Yield” warning comes from a WaitForChild call, may we get the full code please?

It still has the same error, unfortunately

It says, “Infinite yield possible on ‘Workspace.SupremeShocksAll:WaitForChild(“Shirt”)’”

How did you get to Character is the question…

-- ServerScript
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
       local humanoid = character:WaitForChild("Humanoid") --load pause
       print(character)
    end)
end)

--ClientScript
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid") --load pause
print(character)

I only put a very small portion of the script (where the error comes from). I actually asked AI and it actually helped see what I did wrong, but I appreciate the help :slight_smile:

sweet … also noticed this.
else if foundShirt then

did you mean:
elseif foundShirt then

and just an else would have worked here also.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.