Changing from string value to number value

I have a string value object which has a value of 14/60, trying to find a way to turn it into a number value since you cant do wait function with a string value, is there anyway to do it.

If you’re trying to calculate any given expression, you’re better off using someone else’s code because it’s really complicated. If you just want to convert fractions, it’s just x divided by y.

local function fraction(input)
    local x,y = string.match(input, "(%d+)/(%d+)")
    return x/y
end
1 Like

you can do loadstring but as its very dangerous cuz exploiters can use it to hack. i guess try @JarodOfOrbiter’s answer which does seem more resonable tbh

The thread from load string is not from exploiters anymore, because it can only be used on the server. The main threat is from backdoors and similar vulnerabilities in your own scripts and free models. If he did use load string here, he would need to be careful with it. If this string value were based on player input, it could be possible to input malicious code instead of just a fraction, which it would then run.

Actually I don’t know why we’re using a string in the first place. If it isn’t based on player input, it probably shouldn’t be a string.

you can blacklist some characters tbh with simple code but yea your right. and they used strings to make a calculator similar to google calculator. cuz i did made a calculation plugin using loadstring did get critisized alot :frowning:

1 Like

so i was playing round and found a better way

local function fraction(input)
	local args = string.split(input,"/")
	local number = args[1]
	for i = 2,#args do
		number /= args[i]
	end
	return number
end
print(fraction("10/10/10/10"))

answer = 0.01

2 Likes