Problem With Infinite Yield

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix my infinite yield problem.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know how to fix it.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I couldn’t find any solutions.

Client Script

-- Wait for char
game.Players.LocalPlayer.CharacterAdded:Wait()

-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")

-- Modules
local Config = require(script.Parent.Parent.Modules.Config)

-- Tool
local Tool = script.Parent.Parent
local Handle = Tool:WaitForChild("Handle")

-- UI
local UI = Tool.Assets.UI
local CooldownUI = UI.CooldownUI

-- Sword Vars
local Damage = Config.Damage
local Cooldown = Config.Cooldown

-- Player Vars
local player, humanoid, char
player = Players.LocalPlayer
humanoid = player.Character:WaitForChild("Humanoid")

-- Anim Folder
local AnimFolder = Tool.Animations

-- Remotes Folder
local RemotesFolder = Tool.Remotes

-- Remotes 
local SoundPlayer = RemotesFolder.SoundPlayer
local AddCombo = RemotesFolder.AddCombo

-- Sounds Folder
local SoundParent = Tool.Handle



-- Booleans
local isAttacking = false
local canDamage = true

local function onEquip()
	local EquipAnim = AnimFolder:WaitForChild("Equip")
	local EquipTrack = humanoid:LoadAnimation(EquipAnim)
	EquipTrack:Play()
	SoundPlayer:FireServer(SoundParent:WaitForChild("Equip"))
end

local function onUnequip()
	local UnequipAnim = AnimFolder:WaitForChild("Unequip")
	local UnequipTrack = humanoid:LoadAnimation(UnequipAnim)
	UnequipTrack:Play()
	SoundPlayer:FireServer(SoundParent:WaitForChild("Unequip"))
end

-- Attack
local Combo = Tool.Values.Combo

local function Attack()
	local Slash = humanoid:LoadAnimation(AnimFolder:WaitForChild("Slash" .. tostring(Combo)))
	Slash:Play()
	
	Tool.Remotes.ClientCast:FireServer(Slash.Length, Config.Cooldown)
	canDamage = false
	SoundPlayer:FireServer(SoundParent:WaitForChild("Slash"))
	humanoid.WalkSpeed -= Config.WalkSpeed
	humanoid.JumpPower -= Config.JumpPower 
	task.wait(math.max(Slash.Length, Config.Cooldown))
	humanoid.WalkSpeed += Config.WalkSpeed
	humanoid.JumpPower += Config.JumpPower
	canDamage = true
end

UserInputService.InputBegan:Connect(function(input, gameProccessed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and player.Character:FindFirstChild(Tool.Name) then
		if isAttacking == false and canDamage then
				isAttacking = true

				if Combo.Value > Config.MaxComboNumber then
					Combo = 1
				end
			

				Attack()
				isAttacking = false
				AddCombo:FireServer()
		end
	end
end)

Tool.Equipped:Connect(onEquip)
Tool.Unequipped:Connect(onUnequip)

Add Combo

-- Tool
local Tool = script.Parent.Parent

-- Values Folder
local ValuesFolder = Tool.Values

-- Remotes Folder
local RemotesFolder = Tool.Remotes

-- Add Combo Remote
local AddCombo = RemotesFolder.AddCombo

AddCombo.OnServerEvent:Connect(function(Player)
	ValuesFolder.Combo.Value += 1
end)

Output with infinite yield

Infinite yield possible on 'Workspace.SilentDevReal.TestSword.Animations:WaitForChild("SlashCombo")'
1 Like

use :FindFirstChild() instead.

1 Like

Error: LoadAnimation requires an Animation object

1 Like

seems like there is no Anim Called “Slash”…ComboValue

Actually there is since I make them through a script.

I fixed it. I must’ve set Combo.Value and not Combo