I’m trying to “unpack” a table with numbers but separate them with commas for argument purposes to pass, like this. However it returns nil due to the comma.
function Engine:Fire(event:string?, ch, ...):BindableEvent?
-- ... in this case is {15,2}
if event:lower():match("fire") then
_G:ReP(ch.Character, "ev").Burn:Fire(tonumber(table.concat(..., ","))) -- Burn events takes two arguments as number, (10,5), like this.
end
end
The comma is not a number. You cannot use tonumber on a string that contains non-numeric characters.
Also, even if you removed tonumber, you would not be passing two arguments. You would be passing the string “10,5” as one argument.
You must explicitly put a comma in the parentheses between two values yourself, there is no jank way to do it like you’re trying to do it in a single line. Slow down and spread your operations out, don’t cram them all into a single line.
Sorry, was a bit busy, but yes, as biglulu stated, you’re assigning a tuple to a variable, which only takes as many values as you put variables.
The proper way to use this would be in a method like :Fire(table.unpack(…))
local T = {4,3,2,1}
local function FakeFire(...)
local Values = {...} -- We can recompile the tuple (...) to a table with curly braces.
for Which, Value in pairs({...}) do -- We can also iterate the values
print(Which, Value) -- And then print/use them.
end
print(Values)
end
-- Let's simulate :Fire() by calling FakeFire()
FakeFire(table.unpack(T))
-- There you have it.
This worked but is there any way to separate the two with commas so i can pass them as args like I said?
As of @IDoLua, your method worked but on the bindable event function itself it errored Unable to cast Array to float
Burn.Event:Connect(function(Time:number?, Damage:number?)
Humanoid:TakeDamage(Damage or 5) -- Errored.
_G:ReP(Character, "va").BurningTime.Value = Time
end)
Here you go. Keep in mind this only works if the first number and second number are passed in as the first and second argument after ch.
function Engine:Fire(event:string?, ch, ...):BindableEvent?
-- ... in this case is {15,2}
if event:lower():match("fire") then
local arg = {...}
local num1, num2 = table.unpack(arg)
_G:ReP(ch.Character, "ev").Burn:Fire(num1, num2) -- Burn events takes two arguments as number, (10,5), like this.
end
end