Jump to content

GUI double click problem


Recommended Posts

My problem is, when I click on the button 2 which is register then it's click twice on the button, but I only click once, why?

 

function Panel:loginClick(button, state)
	if self.show and self.hovered == 'buttons' and self.selectedbutton == 1 then
		for key, value in pairs(self.loginGuis) do
			if value.text == '' then
				if clickTick + (5000) > getTickCount() then return end
                exports.ml_notification:addNotification('All fields are required!', 'warning')
				destroyAnimation()
				break
			else
				triggerServerEvent('loginaccount', localPlayer, localPlayer, self.loginGuis[1].text, self.loginGuis[2].text)
				destroyAnimation()
			end
		end
	elseif self.show and self.hovered == 'buttons' and self.selectedbutton == 2 then
		for key, value in ipairs(self.registerGuis) do
			if value.text == '' then
				if clickTick + (5000) > getTickCount() then return end
				exports.notification:addNotification('All fields are required!', 'warning')
				break
			else
				if self.registerGuis[2].text == self.registerGuis[3].text then
					if isValidMail(self.registerGuis[4].text) then
                        outputChatBox(self.registerGuis[1].text)
                        triggerServerEvent("registeraccount", localPlayer, localPlayer, self.registerGuis[1].text, self.registerGuis[2].text, self.registerGuis[4].text)
						break
					else
						exports.notification:addNotification('Wrong email!', 'warning')
						break
					end

				else
					exports.notification:addNotification('The passwords do not match!', 'warning')
					break
				end
			end
		end
	end
end

The registeraccount server side:

function registerAcc(player, username, password, email)
    outputChatBox("register clicked")
	local password = base64Encode(password)
	local registerQuery = dbPoll(dbQuery(sql, "SELECT * FROM account"), -1)
	for _, row in ipairs(registerQuery) do
		if row["username"] == username then
            exports.notification:addNotification(player, 'This username is already taken!', 'warning')
			return
		end
		if row["serial"] == getPlayerSerial(player) then
			exports.notification:addNotification(player, 'You already have an account!', 'warning')
			return
		end
	end
	
	local registerInsert = dbQuery(sql, "INSERT INTO account SET username = ?, password = ?, email = ?, serial = ?",
							username, password, email, getPlayerSerial(player))
	local result, num, insertID = dbPoll(registerInsert, -1)
	if insertID then
		exports.notification:addNotification(player, 'Register success!', 'info')
        
	end
end
addEvent("registeraccount", true)
addEventHandler("registeraccount", root, registerAcc)

The problem is because it's clicking on the button twice then always getting a warning notification when I register "You already have an account"

Link to comment

Your error is not using the "state" parameter. Try this:

function Panel:loginClick(button, state)
    if state == "down" then
        if self.show and self.hovered == 'buttons' and self.selectedbutton == 1 then
            for key, value in pairs(self.loginGuis) do
                if value.text == '' then
                    if clickTick + (5000) > getTickCount() then return end
                    exports.ml_notification:addNotification('All fields are required!', 'warning')
                    destroyAnimation()
                    break
                else
                    triggerServerEvent('loginaccount', localPlayer, localPlayer, self.loginGuis[1].text, self.loginGuis[2].text)
                    destroyAnimation()
                end
            end
        elseif self.show and self.hovered == 'buttons' and self.selectedbutton == 2 then
            for key, value in ipairs(self.registerGuis) do
                if value.text == '' then
                    if clickTick + (5000) > getTickCount() then return end
                    exports.notification:addNotification('All fields are required!', 'warning')
                    break
                else
                    if self.registerGuis[2].text == self.registerGuis[3].text then
                        if isValidMail(self.registerGuis[4].text) then
                            outputChatBox(self.registerGuis[1].text)
                            triggerServerEvent("registeraccount", localPlayer, localPlayer, self.registerGuis[1].text, self.registerGuis[2].text, self.registerGuis[4].text)
                            break
                        else
                            exports.notification:addNotification('Wrong email!', 'warning')
                            break
                        end

                    else
                        exports.notification:addNotification('The passwords do not match!', 'warning')
                        break
                    end
                end
            end
        end
    end
end

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...