Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why will this function play when i dont click the gui and when i click other gui buttons????

Asked by 4 years ago

it just seems to keep playing when im not clicking the button

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")
local button_clicked = false
local connection
connection = script.Parent.Activated:Connect(function()
    button_clicked = true
    connection:Disconnect()
    connection = nil
end)

local readz = true 

local function punch(connection,readz, gameProcessed)
    if connection ~= nil and readz then
        punchEvent:FireServer()
        local button_clicked = false
        readz = false
        wait(0.5)
        readz = true
       print("clicked!!")
    end
end
UserInputService.InputBegan:Connect(punch)
-----------------

Answer this question