Button event wont go through my if statements even though it is either true or false

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’m trying to make a trade system but every time a I click the button to select a pet to trade it doesn’t pass/enter the if statements

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

The if statements arent being entered even if its true (Two statements both checking if true or false)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I haven’t found anything on the devforum that would help.

I’m using a TextButton
image

newFrame.Click.MouseButton1Up:Connect(function()
	print(1)
	if newFrame.Checked.Value == true then
		print(5)
		local success, message = TradeEvents.RemovePetFromTrade:InvokeServer(newFrame.Name, i)

		if not success then
			print(6)
			print(message)
		else
			print(7)
			newFrame.Icon.Visible = false
		end
	elseif newFrame.Checked.Value == false then
	    local success, message = TradeEvents.AddPetToTrade:InvokeServer(newFrame.Name, i)
	    print(2)
	    if not success then
		  print(3)
		  print(message)
	elseif success then
		print(4)
		newFrame.Icon.Visible = true
	end
end
print(0)
newFrame.Checked.Value = not newFrame.Checked.Value
end)

Thanks,
Indelton!

It’s because you put MouseButton1Up, you should put MouseButton1Click

I used MouseButton1Click and it still didn’t work!

The first thing you should do is simplify the script so it’s easier to read.
This could be your problem straight off of the bat.
Turn

if value == true then

To

if value then 
if not value

Okay I tried it and it worked so thankyou every much!

You should always check your grammar in scripts! :grinning: