MouseButton1Down repeating an additional time it's pressed

I’m trying to make a system that randomly generates two numbers, and the player must determine which number is bigger or smaller. I use math.random to determine whether the question would be whether the comparison would determine if both numbers are bigger or smaller. Each time I solve a question, and choose the prompt to solve it again, when I’d press the button (the button that I’m having trouble with) it would trigger the event an additional time. (5 trials = 5 prints)

I haven’t found an error like this on DevForums, however I may have missed something. If anyone requires the full script, I can surely post it here.

facprompt.Lvl2.MouseButton1Down:Connect(function()
      --script trigger
end)
1 Like

Try MouseButton1Click instead of MouseButton1Down.
Alternatively MouseButton1Up might fix this too.
Other than that I can only assume that either your Gui handler script has 2 copies or your mouse is mechanical and is sending 2 mouse clicks.

1 Like

Try this:

local bignumber = 0
local smallnumber = 0

facprompt.Lvl2.MouseButton1Down:Connect(function()
  local number1,number2 = math.random(1,10),math.random(1,10)
  if number1 > = number2 then
    bignumber = number1
    smallnumber = number2
   else
    bignumber = number2
    smallnumber = number1
  end
end)

wait nvm, whats your error in your script?

I have debounce on the button, so more than 1 mouse click at a time shouldn’t be the problem. I tried MouseButton1Click, and MouseButton1Up, however they didn’t work.

1 Like

My problem isn’t with figuring out how to determine which of two values is bigger, my problem is that when I press the button it triggers an additional time it’s pressed. For example with your code, line 5 would repeat an additional time giving me a different number each time.

Do you have any task.wait() function, if yes remove it, I don’t think scripters can solve it, if its not related to script, its about bug

report it in #bug-reports ,if you don’t have access to it, then message bug reporter in devforum

1 Like

Possibly try .Activated instead of .MouseButton1Down.