How to use if (math.clamp) properly [Need Help ASAP]

Hello I am currently making a discord application but on roblox so I wanted to get a discord id, and the discord id is only 18-digits, here is what I tried but didn’t work

local TextBox = script.Parent.Textbox
local Button = script.parent

submitbutton.MouseButton1Click:Connect(function()
     if (math.clamp(tonumber(TextBox.Text),1000000000000000000,999999999999999999)) then
         Button.Text="Submitted"
     elseif not math.clamp(tonumber(TextBox.Text),1000000000000000000,999999999999999999)) then
         Button.Text="Id Must Be 18-Digits"
     end
end

When I pressed the button it says submitted even if digit is lower than 18

You could just check if the string text has less than 18 character’s

if #TextBox.Text < 18 then
   print("Id must be 18 digits.")
end

Also, math.Clamp just returns a number between the minumum and maxiumum number’s provided, so it could never be false or nil.

Or alternatively check if it’s within 18 - 19 digit number

local Min = 10 ^ 18 --18 digit number
local Max = 10 ^ 19 --19 digit number

local num = tonumber(TextBox.Text)

if num < Max and num >= Min then
   print("Submitted")
else
   print("Nop")
end
1 Like

Thanks for the help but somehow it stills prints submitted

What does the code look like now?

1 Like

Somehow the output is submitted and btw the script I showed is a sample, but the code is fully needed I can give it to you

I am just gonna give it

here you go

local submitbutton = script.Parent.Submit
local ws = require(script.Parent.WebhookService)

local url = "can't give :)"
local Players = game:GetService("Players")
local Hellotext = script.Parent.UserName
--local optionaltextval = script.Parent.PlayerSaying
local userid =game:GetService("ReplicatedStorage"):WaitForChild("DiscordId")
local PlayerSaid = game:GetService("ReplicatedStorage"):WaitForChild("PlayerSaying")
local TweenService = game:GetService("TweenService")
local textboxclosed = UDim2.new(1.5, 0,0.331, 0)
local discordidclosed = UDim2.new(1.5, 0,0.808, 0)
local submitshowppsitoin = UDim2.new(0.063, 0,0.422, 0)
local DiscordButtonTween = TweenService:Create(script.Parent.DiscordID, TweenInfo.new(1), {Position=discordidclosed})
local textboxTween = TweenService:Create(script.Parent.TextBox, TweenInfo.new(1), {Position=textboxclosed})
local submitshow = TweenService:Create(script.Parent.SubmittedText, TweenInfo.new(1), {Position = submitshowppsitoin}) 

local peoplewhoapplied = {}



submitbutton.MouseButton1Click:Connect(function(player)
	for _, p in pairs(Players:GetPlayers()) do
		local useridint = tonumber(userid.Value)
		if (tonumber(userid.Value))then
			
			if table.find(peoplewhoapplied, useridint) then
				p:Kick("Apparently The Id You Entered Is Already Verified, Screenshot This If Your Not Verified")
			elseif not table.find(peoplewhoapplied, userid.Value)  then			
				if useridint<18 then
					
					if userid.Value=="" then
						submitbutton.Text="Error"
						wait(1.5)
						submitbutton.Text="Submit"
					elseif userid.Value~="" then
						submitbutton.Text="Submitted"
						local playername = p.Name
						local playeruserid = p.UserId
						textboxTween:Play()
						DiscordButtonTween:Play()
						submitshow:Play()
						submitbutton.Visible=false
						local fields = {
							{
								['name'] = playername.." said nothing",
								['value'] = "Submitted By: "..playername.." | "..playeruserid,
								['inline'] = true
							}
						}
						local digit = math.clamp(useridint,1000000000000000000,999999999999999999)
						print(userid)
						ws:createEmbed(url, "New Application", "Submitted By <@"..userid.Value..">", fields)
						wait(3.5)
						p:Kick("Application Submitted Succesfully")
					end
						
				elseif useridint>18 then
					submitbutton.Text="Digit Number Should Be 18 digits"
					wait(2.5)
					submitbutton.Text="Submit"
				end
				
			end	
		else	
			submitbutton.Text="Error"
			wait(1.5)
			submitbutton.Text="Submit"
		end
		
end
	
	
		
	
	
end)




	

and sorry if you didn’t understand the code, I am currently learning lua

Have you tried printing useridint? You should more be counting the amount of characters are in the string actually than checking if the number is less or above 18

1 Like

if I entered 18 digits it comes out as 111111111111111111
but if I entered more than 18 it comes out as 111111111111111200

that’s what it printed

but now it keeps saying digit must be 18 digits when I press the button

which means it is going through

elseif useridint>18 then
      submitbutton.Text="Digit Number Should Be 18 digits"
	  print(useridint)
	  wait(2.5)
	  submitbutton.Text="Submit"
end

Oh right when the value was empty it said error

Hey iii but i do not know how and what is !!

1 Like

it’s ok thanks for replying @TenBlocke showed me that I shouldn’t use math.clamp which I found it correct, now I am trying to see how to know if the input is 18 digits and I am trying to use if statement on that

Again, you could just check with either of the ways I’ve provided in the original reply.

oh right I forgot to check the second code u sent, I will check it now

When I use the code you gave me, it only works when the digit is 20

local Min = 10 ^ 18 --18 digit number
local Max = 10 ^ 19 --19 digit number

local num = tonumber(TextBox.Text)

if num < Max and num >= Min then
   print("Submitted")
else
   print("Nop")
end

If I made min = 10^15
and max 10^16 it accepts 17 and 18

If you’re using actual Discord’s snowflake ids, pretty much the best case scenario is learning how the id is structured.

Because it’s a uint64 type (basically 64-bits for a positive-only integer) and roblox numbers are handled by floats, trying to pull it off is going to be tricky as the bit32 library only supports 32 bit operations and you have to deal with Floating point rounding if you ever dare try to turn it into numbers.

Simply put, it’s going to be difficult for newbies.

1 Like