Infinite yield in animations

Hello devs,

Once again im asking for your support

Recently I decided to rewrite my combat system in my fighting game but i have come across a error claiming there is a infinite yield in my code about a kick animation

There is animations folder in the script with all my animations but says "Infinite yield possible in ServerScriptService.Combat_System.Animations:WaitForChild(“Kick”)

When its in there and has the exact name
Server Code

local rp = game:GetService("ReplicatedStorage")
local Combat = rp:WaitForChild("Combat")



local animations = script:WaitForChild("Animations")


local anims = 
	{
		animations:WaitForChild("Right"),
		animations:WaitForChild("Left"),
		animations:WaitForChild("Kick"),
		animations:WaitForChild("Heavy Attack"),		
	}


Combat.OnServerEvent:connect(function(player,count)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	
	local attack = humanoid:LoadAnimation(anims[count])
	attack:Play()
	
	Combat:FireClient(player)
end)

Client Code

local player = game:GetService("Players").LocalPlayer

local rp = game:GetService("ReplicatedStorage")
local Combat = rp:WaitForChild("Combat")

local UIS = game:GetService("UserInputService")

local Mouse = player:GetMouse()

local debounce = false

local cd =.25

local currtime = 0
local prevtime = 0
local count = 0 



UIS.InputBegan:connect(function(input,istyping)
	if istyping then 
		return
	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		if debounce == false then
			debounce = true
			currtime = tick()
			
			local passedtime = currtime - prevtime
			if passedtime < 1 then
				count = count + 1
				if count > 4 then
					count = 1 
				end
			else count = 1
			end 
			
			Combat:FireServer(count)
		end
	end
end)

Combat.OnClientEvent:Connect(function()
	wait(cd)
	debounce = false
end)

Thanks for reading
~Neptune

1 Like

That warning occurs only when you are trying to WaitForChild() for an object, that is not there for extended period of time.
There are two possible endings:

  1. The object will be found after some time and the script will continue
  2. The object will never show up in there and the script will get yielded.

To ensure you are doing everything correctly you can print out tha instance you are trying to search the object in. Then you can check the name once again.

I hope this was helpful!
Have a nice day!

3 Likes

Gotta be number two since the script isn’t working anyway to fix this?

I already wrote the possible sloutions to this problem in my previous answer.

Also, I have noticed you are using a comma in here, which will result in an error, as it’s the last item in the table.

1 Like

Having a comma on the last index in a table won’t result in an error

4 Likes

Alright it’s now playing the anim but it’s only the punch and the other anims arnt playin any fix?

Oh thank you for letting me know that. I thought I have done that in past and it gave me an error.

1 Like

It does but in his case it wont

Can you send a screenshot of the Animations folder?

1 Like

You are not updating the prevtime so it will always be giving you more than one and therefore the count will always remain 1 which only plays the punch animation. To fix this you would need to add

prevtime = tick()

somewhere within your code

1 Like

Nope still the same anim playing

Can’t do a screenshot by here is how is looks

^Animations
Heavy attack
Kick
Left
Right

Can you rename the Kick animation and ensure the name is only Kick with no other characters?

The kick animation problem is over but now it’s just the others anims ain’t playing