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

Why wont my function play??? it wont even print!

Asked by 4 years ago

im not great at script guis but i made this little punch thing but the function wont play when i click the button.. pls help!

--Made by ParionFire
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")
local Button = script.parent.MouseButton1Down

local ready = true

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

1 answer

Log in to vote
0
Answered by 4 years ago

How to use events

You connect to them. You don't use them as conditions. You're explicitly comparing it to true, which Button == true immediately evaluates to false.

You can do something like this though:

local button_clicked = false
-- Don't use MouseButton1Down. Think of your mobile and console players!
local connection
connection = script.Parent.Activated:Connect(function()
    button_clicked = true
    connection:Disconnect()
    connection = nil
end)

And in your control structure:

if button_clicked and ready then
    -- thing
end
Ad

Answer this question