I’m creating a TextBox UI element which allowed the player to change the transparency of a part. However, it isn’t working as intended. I believe this is due to the “.” in decimals such as “0.5” The script checks to make sure the string is a number. I think it might be reading the “.” as a string period instead of a numeric dot. (I could be wrong about this)
- Must ensure the input is between 0 and 1
- Must ensure the input is a number
local LocalPlayer = game:GetService("Players").LocalPlayer
local inputBox = script.Parent.InputBox
local function changeTransparency()
local userInput = inputBox.Text
local isInteger = tonumber(userInput) ~= nil and math.floor(tonumber(userInput)) == tonumber(userInput)
local isValidDecimal = tonumber(userInput) ~= nil and tonumber(userInput) >= 0 and tonumber(userInput) <= 1
if isInteger and isValidDecimal then
print("Success!")
else
print("Fail!")
end
end
inputBox.FocusLost:Connect(changeTransparency)
0 and 1 both print “Success!”
Every other number such as 0.5 or 0.2 prints “Fail!” Any ideas?