Error for infinite yield


What does this error mean? I don’t understand what it means for Infinite yield and the code at the bottom is the code I made for doing a pet system which basically a pet follows you along let pet simulator x. If you need anything more than that, I am happy to screenshot and explain to you the code that I did.

game.ReplicatedStorage.Spawnpet.OnServerEvent:Connect(function(player)
	local character = game.Workspace:WaitForChild(player.Name)
	local humanoidrootpart = character:WaitForChild("HumanoidRootPart")
	local part = character:WaitForChild(player.Name.."Parts")
	local alignori = Instance.new("AlignOrientation",character)
	local alignpos = Instance.new("AlignPosition",character)
	local pet = game.ReplicatedStorage.Petforgui:Clone()
	pet.CFrame = part.CFrame
	pet.Parent = game.Workspace
	
	alignpos.Attachment0 = pet.Attachment
	alignpos.Attachment1 = part:WaitForChild("Attachment")
	alignpos.MaxForce = 100000
	
	alignori.Attachment0 = pet.Attachment
	alignori.Attachment1 = part:WaitForChild("Attachment")
	alignori.MaxTorque = 100000
end)
1 Like

It basically means it can’t find flxvershellyqsParts, or basically, it can’t find player.Name.."Parts"
Make sure it exists inside of the character, try looking at the explorer.

Oh. I think I know the problem now. Because in my code I didn’t put the part to respawn if the player resets the character but idk how to do so. Can you please help me? This is the code for the part

game.Players.PlayerAdded:Connect(function(player)
	
	local part = Instance.new("Part")
	part.Size = Vector3.new(0.5,0.5,0.5)
	part.Transparency = 1
	part.CanCollide = false
	part.Anchored = false
	part.Massless = true
	part.Name = player.Name.."Parts"
	local attachment = Instance.new("Attachment")
	attachment.Parent = part
	local humanoidrootpart = game.Workspace:WaitForChild(player.Name):FindFirstChild("HumanoidRootPart")
	part.CFrame = humanoidrootpart.CFrame * CFrame.new(-2.689, -2.636, 0.112)
	part.Parent = game.Workspace:WaitForChild(player.Name)
	
	
	local weld = Instance.new("WeldConstraint")
	weld.Parent = game.Workspace:WaitForChild(player.Name)
	weld.Part0 = part
	weld.Part1 = humanoidrootpart

end)

You can simply use the CharacterAdded event of a Player. This is how you can do it:

local function createPart(player)
    local part = Instance.new("Part")
    part.Size = Vector3.new(0.5,0.5,0.5)
    part.Transparency = 1
    part.CanCollide = false
    part.Anchored = false
    part.Massless = true
    part.Name = player.Name.."Parts"
    local attachment = Instance.new("Attachment")
    attachment.Parent = part
    part.Parent = game.Workspace

    local character = game.Workspace:WaitForChild(player.Name)
    local humanoidrootpart = character:FindFirstChild("HumanoidRootPart")
    if humanoidrootpart then
        part.CFrame = humanoidrootpart.CFrame * CFrame.new(-2.689, -2.636, 0.112)

        local weld = Instance.new("WeldConstraint")
        weld.Parent = part
        weld.Part0 = part
        weld.Part1 = humanoidrootpart
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        createPart(player)
    end)
    createPart(player)
end)

What I did is convert your Part Creation into a function, and connected it to both when the player respawns and when the player joins.

1 Like

Thank you! I didn’t know that there is a characteradded event :sweat_smile:

1 Like

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