Hi! I have code spanning two modules:
debounce = function(duration: number, is_per_player: boolean, rejection_callback)
local global_debounce: boolean = false
local local_debounce = {}
return function(plr, model, action_id)
if is_per_player and not local_debounce[plr] then
local_debounce[plr] = true
task.delay(duration, function()
local_debounce[plr] = nil
end)
return true
elseif (not is_per_player) and not global_debounce then
global_debounce = true
task.delay(duration, function()
global_debounce = false
end)
return true
end
if rejection_callback then
rejection_callback(plr, model, action_id)
end
return false
end
end
action_service:observe_action(function(plr, model)
if not model:GetAttribute("store_lights") then return end
model:SetAttribute("on", not model:GetAttribute("on"))
end, "toggle_store_light_lever", {
action_service.filters.expect_model(false),
action_service.filters.debounce(COOLDOWN, true, function(plr)
notification_service:local_notification(plr, {
title = "Error",
description = "Lights are on cooldown",
})
end),
})
The function on the first module is called by the second module
action_service.filters.debounce(COOLDOWN, true, function(plr)
notification_service:local_notification(plr, {
title = "Error",
description = "Lights are on cooldown",
})
end),
However, I’m getting a typing error:
TypeError: Type
‘<a, b>(any, a, b) → boolean’
could not be converted into
‘<a, b, c>(a, b, c) → boolean’; different number of generic type parametersLuau1000TypeError: Type
‘<a, b>(any, a, b) → boolean’
could not be converted into
‘<a, b, c>(a, b, c) → boolean’
caused by:
Argument #2 type is not compatible.
Type ‘a’ could not be converted into 'a’Luau1000
If found out that if I move:
local local_debounce = {}
into the scope of the return function like so, the error goes away:
return function(plr, model, action_id)
local local_debounce = {}
if is_per_player and not local_debounce[plr] then
local_debounce[plr] = true
task.delay(duration, function()
local_debounce[plr] = nil
end)
return true
elseif (not is_per_player) and not global_debounce then
global_debounce = true
task.delay(duration, function()
global_debounce = false
end)
return true
end
if rejection_callback then
rejection_callback(plr, model, action_id)
end
return false
end
but obviously that breaks the logic of my code. I’m not sure if I’ve done anything wrong. How can I solve the error?