Why does this not work?

so i have made a script that fire an event based on a leaderstat and the number entered, but this does not work and i cannot figure out why since there is no errors

local function dropping(Resource)
	 if not button.Parent.TextBox == nil then
		local number = button.Parent.TextBox.Text
			if tonumber(number) <= tonumber(Resource) then
			print("yesss")
			--drop:FireServer("Wood", number)
		elseif tonumber(number) >= tonumber(Resource) then
			button.TextColor3 = Color3.new(0.985946, 0, 0.0406043)
			button.Text = "INVAILD NUMBER"
			wait(2)
			button.TextColor3 = Color3.new(255,255,255)
			button.Text = "Drop"
		end
	end
end
button.MouseButton1Click:Connect(function()
	if Text == "Dropping: Wood" then
		dropping(player.Resources.Wood.Value)
	end
end)

Have you tried debugging? Try to print out some values and see what returns

Example, try to print those:

print(number)
print(Resource)
print(button.Text)

Try to print them at any step in your code to see what returns to you, and see if there are any errors.
Also,
1.Use task.wait instead of wait.
2.tonumber(Resource) no need to do that, since Resource represents an intvalue / numbervalue [ hope so], it is already a number.

2 Likes

ill try that once i get home, thanks

1 Like
if Text == "Dropping: Wood" then

There’s a good chance that this if statement’s condition is not being satisfied (never evaluating to true).

nope, i added a print statement and it printed, it just didn’t detect the number, it didn’t do anything when it is a invaild text and it didn’t

Try changing if not button.Parent.TextBox == nil then to:
if button.Parent.TextBox ~= nil then