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

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

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 comment

1 answer

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

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