Corountine.yield not working

My goal is to loop the function when the button is hold but the loop !

the script never stops looping

Screenshot (10)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here the script

--[[
this allows the developer to create their Input in a more advanced way

example:

SyncUserInput:KeyCodeHold(Enum.KeyCode.R,0.03,function (typeOfInput)
	if typeOfInput == "Hold" then 
		warn("R Holding")
	end
	
	if typeOfInput == "Released" then
		warn("R Released")
	end
end)

SyncUserInput:KeyCodeReleased(Enum.KeyCode.R,0.03,function (typeOfInput)
	warn("R KeyCode Released")
end)

SyncUserInput:UserInputTypeReleased(Enum.UserInputType.MouseButton1Up,0.03,function (typeOfInput)
	warn("MouseButton1Up UserInputType Released")
end)

SyncUserInput:UserInputTypeHold(Enum.UserInputType.MouseButton1Up,0.03,function (typeOfInput)
	if typeOfInput == "Hold" then 
		warn("MouseButton1Up UserInputType Holding")
	end
	
	if typeOfInput == "Released" then
		warn("MouseButton1Up UserInputType Released")
	end
end)




SyncUserInput:DisconnectSignal(Signal)

]]

--Services:

local UIS = game:GetService("UserInputService")

--Module assets:

local SyncUserInput = {}

--Corountine manager:

function pause(studio)
	coroutine.yield(studio)
end

function resume(studio)
	coroutine.resume(studio)
end

function create(func)
	return coroutine.create(func)
end

function getStatus(co)
	return coroutine.status(co)
end

function SyncUserInput.KeyCodeHold(KeyCode,duraction,func)
	local typeOfInput = nil
	local co = create(function() 

		while wait(duraction)do 
			local typeIn = typeOfInput 
			func(typeIn) 
		end

	end)

	local inpBegan = UIS.InputBegan:Connect(function(inp)
		if inp.KeyCode == KeyCode then
			co = function() 
				spawn(function()
					while wait(duraction)do 
						local typeIn = typeOfInput 
						func(typeIn) 
					end
				end)
			end
			resume(co)
		end
	end)

	local inpEnded = UIS.InputEnded:Connect(function(inp)
		if inp.KeyCode == KeyCode then
			pause(co)
		end
	end)

	return {Hold = inpBegan,Released = inpEnded,coroutine = co}
end

function SyncUserInput.UserInputTypeReleased(UserInputType,func)
	local co = nil

	local inpEnded = UIS.InputEnded:Connect(function(inp)
		if inp.UserInputType == UserInputType then
			co = create(function()  func()   end)
			resume(co)
		end
	end)

	return {Released = inpEnded,coroutine = co}
end

function SyncUserInput.UserInputTypeHold(UserInputType,duraction,func)
	local co = nil
	co = create( function() 
		spawn(function()
			while wait(duraction) and getStatus(co) ~= "dead" do 

				func() 
			end
		end)
	end)

	local typeOfInput = nil

	local inpEnded = UIS.InputEnded:Connect(function(inp)
		if inp.UserInputType == UserInputType then
			pause(co)
		end
	end)
	
	local inpBegan = UIS.InputBegan:Connect(function(inp)


		if inp.UserInputType == UserInputType then
			typeOfInput = inp

			resume(co)
		end
	end)

	return {Hold = inpBegan,Released = inpEnded,coroutine = co}
end

function SyncUserInput.KeyCodeReleased(KeyCode,func)
	local co = create(function()  func()   end )

	local inpEnded = UIS.InputEnded:Connect(function(inp)
		if inp.KeyCode == KeyCode then
			resume(co)
		end
	end)

	return {Released = inpEnded,coroutine = co}
end

function SyncUserInput.DisconnectSignal(Signal)
	spawn(function()
		if Signal.Hold then
			Signal.Hold:Disconnect()
		end
	end)

	spawn(function()
		if Signal.co then
			pause(Signal.co)
		end
	end)

	spawn(function()
		if Signal.Released then
			Signal.Released:Disconnect()
		end
	end)
end

function format:GetPlayerControl()
		local plrModule = nil

		local suc, err = pcall(function()
			plrModule = require(player:FindFirstChild("PlayerScripts"):FindFirstChild("PlayerModule"))
		end)

		if suc then
			return plrModule:GetControl()
		else
			warn(("Error on :GetPlayerControl(%s)"):format(err))
		end
	end

	player.CharacterRemoving:Connect(function()
		format.Character = nil
		format.Character = player.CharacterAdded:Wait()
	end)

	return format
end

return SyncUserInput

Maybe I’m dumb, but I don’t see a SyncKeyCodeHold function anywhere in that module.

Did you write this module and you’re asking to debug it? Or are you just asking how to use it?

I forgot i changed it to KeyCodeHold