Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)
-----------------

1 comment

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.

1 answer

✓ Accepted answer
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.

2 comments

0

thanks but it plays the function when the buttons not clicked and stop it when it is....

0

nvm i found it out thx!

This discussion is preserved as it was. New answers, comments, and votes are closed.