Well, I want a condition not to be executed if the textbox has the same number as a NumberValue Value, I already use if (DivideButton.Text ~= "") and (not DivideButton.Text == selected.Value.Stack.Value) then or if (DivideButton.Text ~= "") and (DivideButton.Text ~= selected.Value.Stack.Value) then
but doesn’t work
local selected = script.Parent.Parent.Handler.Selected
local DivideButton = script.Parent.Divide
DivideButton.FocusLost:Connect(function(enterPressed)
if enterPressed then
if selected.Value ~= nil and selected.Value:FindFirstChild("Stack") then
DivideButton.Text = DivideButton.Text:gsub('%D+', '')
if (DivideButton.Text ~= "") and not (DivideButton.Text == selected.Value.Stack.Value) then
ReplicatedStorage.InventoryFunctions:FireServer("DivideService", selected.Value, nil, DivideButton.Text)
end
end
end
end)
This is because you are trying to compare a string to a number. Roblox doesn’t automatically convert the number to a string and vice-versa. To fix your script replace the if statement with this one:
if (DivideButton.Text ~= "") and not (DivideButton.Text == tostring(selected.Value.Stack.Value)) then
Sorry for the inconvenience, but I also want the condition not to be triggered if the text of the TextBox is 0, I guess it would be like this (and that’s how it works):
if (DivideButton.Text ~= "") and not (DivideButton.Text == tostring(selected.Value.Stack.Value)) and not (DivideButton.Text == tostring(0)) then
But as you can see, it is too long. Try putting change it like this:
if (DivideButton.Text ~= "") and not (DivideButton.Text == tostring(selected.Value.Stack.Value)or "0") then
and also like this: if (DivideButton.Text ~= "") and not (DivideButton.Text == tostring(selected.Value.Stack.Value)or tostring(0)) then
Just letting you know, if the text in the TextBox | Roblox Creator Documentation is supposed to be a number value then you can make sure of that with tonumber on the text instead of tostring on the number. Also, string.len gets the amount of characters in the string. In short, what you need is this:
local text = DivideButton.Text
local txtNum = tonumber(text)
if text:len() > 0 and txtNum ~= 0 and txtNum ~= selected.Value.Stack.Value then