Issues with time converting

I am aware but I can’t seem to find out why. I think it is my time converting

1 Like

Print both values, determine which is nil and which isn’t.

1 Like

BanTime appears to be the one to error any ideas?

playerProfile.Data.BanTime = convertTime(time)

Something going wrong here then, check the function over.

Errors messages for operations in Luau are non-commutative so it’s easy to find out which data type is which. The first operand is a “number” and the second operand is “nil”.


To OP: What is the value of the variable time in convertTime(time)? It looks like the convertTime function returns nil.

Also avoid using time as a variable, it’s getting flagged as reserved.

1 Like

The time variable is the input text the user puts example: “1d” which my convertTime function is suppose to change to seconds

You to need to wrap it inside a call to “tonumber()” so that its type is correctly changed before performing any arithmetic operations on it.

Where? In the convert function I need it to be a string

What type of format does the value “time” typically use? Would help out a lot.

image

print(time)
print(asda)

I know you’re overriding time but you should still avoid using time. And let me know what format “time” is in when its being passed to the function.

So it takes like “1d” and will split the string looking for the number, if it is d then it does the amount of seconds in a day (86400) times the number provided, then returns it in seconds

Yeah, try a print on seconds before it’s returned.

function convertTime(time)
	local day = 86400
	local hour = 3600
	local minute = 60
	local seconds = 1
	local lengthNumber = tonumber(string.match(time, "%d+"))

	local time = string.lower(time)
	if string.find(time, "s") then
		seconds = lengthNumber * 1
	elseif string.find(time, "m") then
		seconds = lengthNumber * minute
	elseif string.find(time, "h") then
		seconds = lengthNumber * hour
	elseif string.find(time, "d") then
		seconds = lengthNumber * day
	end

	print("Convert time")
	return seconds
end

print(convertTime("25d"))

The function is working for me actually.

I see why it’s because “seconds” was out of scope when you attempted to return it, I’ve fixed that by adding “local seconds = 1” so that when the return statement is executed “seconds” is in scope.

Now it works, but if I do “1d” is only bans says 1 second.

image

Must be some other issue on your end.

And that was using my function and it worked? Strange…

I copied the exact thing from what you put and still will not work just shows 1

I’m assuming the data you’re passing to the function is incorrect, look at the way in which I called the function.

1 Like