Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Some weird issue with arguments and parameters?

Asked by 4 years ago
Edited 4 years ago
local DebounceCreator = {}
local ParameterRequest = require(game.ServerStorage.Parameter)


DebounceCreator.Debounce = function(waitTime, f, argument)
    local executing = false
    return function()
        if not executing then
            executing = true
            if next(argument) ~= nil then
                argument = ParameterRequest:new(argument)
                f(argument:unpack())
            else
                f()
            end
            wait(waitTime)
            executing = false
        end
    end
end

No need to know what ParameterRequest does I think, I'm getting an error at

            if next(argument) ~= nil then
                argument = ParameterRequest:new(argument)
                f(argument:unpack())
            else
                f()
            end

however if I change it to:

            if next(argument) ~= nil then
                foo = ParameterRequest:new(argument)
                f(parameter:unpack())
            else
                f()
            end

For some reason changing the name of 'argument' to 'foo' makes the code work all of a sudden. Why is this so?

0
What is the error you're receiving? youtubemasterWOW 2741 — 4y
0
15:09:00.044 - Workspace.Part.OnTouch:13: bad argument #3 (Color3 expected, got nil) I only get this error when it's argument = ParameterRequest:new(argument) but for some reason changing it to foo = ParameterRequest:new(argument) removes that error and the code works perfectly, no logical error or anything.  Physosear 10 — 4y
0
If it works fine with "foo", then just use "foo". youtubemasterWOW 2741 — 4y
0
well, there has to be a reason for why it works that way... Which is what I'm looking for, any other variable name works except itself Physosear 10 — 4y
View all comments (3 more)
0
This is just a guess but maybe "argument" is a term for some other thing so it gets confused when you use that. Try using other things that aren't argument and see if they work. Swaggyguy229 7 — 4y
0
Didn't work, changed the name of argument to some other name and it still didn't work. Maybe it has something to do with closures? Physosear 10 — 4y
0
holy son of god i finally figured out the problem Physosear 10 — 4y

Answer this question