Coroutine not returning a value and the remotefunction's return value is {}

I made a coroutine function to multitask the execution of this script, but the coroutine returns {} instead of data and it’s getting data correctly from the module, the data returned to client by remotefunction is also {}.

Remotes.Player.Ability.OnServerInvoke = function(player, abilityEnum)
	local finalData = {}
	if not debounce[player] then
		coroutine.resume(coroutine.create(function()
			debounce[player] = true
			local data = AbilityModule[abilityEnum](player)
			finalData = data
			task.wait(data.cooldown)
			debounce[player] = false
		end))
	end
	return finalData
end

Instead of all that try coroutine.wrap or task.spawn. Could also note that debounce[player] is nil or false.

Also, #help-and-feedback:scripting-support

Same error even with task.spawn, i still get a empty table, + if i try print() function inside of task.spawn or coroutine it doesnt print anything in output.

Then debounce[player] is nil or false. Easy.

i tried this, still nothing inside task.spawn doesn’t print

	local finalData = {}
	
	if debounce[player] == nil then
		debounce[player] = false
	end
	
	print(debounce[player])--prints false
	
	if not debounce[player] then
		print(debounce[player]) --it prints false here
		task.spawn(function()
			debounce[player] = true
			local data = AbilityModule[abilityEnum](player)
			print("Executing")--doesn't print
			finalData = data
			print(finalData)
			task.wait(data.cooldown)
			debounce[player] = false
		end)
	end
	return finalData

The issue was that it was sending data before receiving it from the modulescript. I added a bindable event to check when the data is ready.

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