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

Why wont my function in a gui button play????? it wont even print

Asked by 5 years ago

i made this attack script for a gui buttom but it wont play the function...

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")
local Button = script.parent.MouseButton1Down
local button_clicked = true
-- Don't use MouseButton1Down. Think of your mobile and console players!
local connection
connection = script.Parent.Activated:Connect(function()
    button_clicked = false
    connection:Disconnect()
    connection = nil
end)

local ready = true

local function punch(inputObject, gameProcessed)
if connection == true and ready then
        print("uhhhh workin")
        punchEvent:FireServer()
        ready = false
        wait(0.5)
        ready = true
    end
end
UserInputService.InputBegan:Connect(punch)
-----------------
0
hey you actually can use MouseButtonDown because you can make separate functions for mobile and console players, such as for mobile you would use contextactionservice and for console you can add in the controller buttons. ahsan666666666666 264 — 5y

1 answer

Log in to vote
0
Answered by
Robin5D 186
5 years ago
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")
local Button = script.parent.MouseButton1Down
local button_clicked = true
-- Don't use MouseButton1Down. Think of your mobile and console players!
local connection
connection = script.Parent.Activated:Connect(function()
    button_clicked = false
    connection:Disconnect()
    connection = nil
end)

local ready = true

local function punch(inputObject, gameProcessed)
if connection ~= nil and ready then
        print("uhhhh workin")
        punchEvent:FireServer()
        ready = false
        wait(0.5)
        ready = true
    end
end
UserInputService.InputBegan:Connect(punch)
-----------------

This should work.

0
thanks but it plays the function when the buttons not clicked and stop it when it is.... Deinonychusaurus 21 — 5y
0
nvm i found it out thx! Deinonychusaurus 21 — 5y
Ad

Answer this question