ServerScriptService.ChatHandler:194: invalid argument #2 to 'tonumber' (base out of range)?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want my fling command to actually work, instead of erroring all the time

  2. What is the issue? Include screenshots / videos if possible!

This chunk here:

elseif Command == "J:Fling" then
				local Target = ArgsTable[2]
				if Target == "all" then
					for indexPlayer, Player in pairs(game.Players:GetPlayers()) do
						local Character = Player.Character
						if Character then
							local HRP = Character:WaitForChild("HumanoidRootPart")
							HRP.Velocity = Vector3.new(0, tonumber(ArgsTable[3], 0))
						end
					end
				else
					local Found_Player = MainModule.FindClosestMatchString("PlayerSearch", game.Players:GetPlayers(), Target)
					if Found_Player then
						local Character = Found_Player.Character
						if Character then
							local HRP = Character:WaitForChild("HumanoidRootPart")
							HRP.Velocity = Vector3.new(0, tonumber(ArgsTable[3], 0))
						end
					end
				end

Is causing the error in the title

I’m not sure why tonumber is failing, it never does this

1 Like

I’m not sure but it can be caused by that you are giving two arguments to it
tonumber(ArgsTable[3], 0) Try fix it to tonumber(ArgsTable[3])

If this do not help try printing out the ArgsTable[3] maybe it would be nil

3 Likes

I think your right :man_facepalming: of course tonummber() only takes one argument. I think that 0 was supposed to be applied to my vector3 parameters as a z value. I’ll check it out later and mark it a solution if ur right

Well, you’re half right. tonumber accepts two arguments: a string and an optional base of the number. The second argument is the cause of the problem and extra arguments would be ignored if you pass them to a function and would just take in the string and it wouldn’t error, but that’s not the case

The base parameter as mentioned before is an optional parameter, which specifies the base of the number which defaults to 10 (decimal system). Base 0 doesn’t exist nor would it make any sense, hence why tonumber throws that error

1 Like