When I click Q nothing happens

local player = script.Parent

local character = player:WaitForChild("Character")

local anims = character:WaitForChild("Anims")

local ui = game:GetService("UserInputService")

local rightarm = character:WaitForChild("RightArm")

local leftarm = character:WaitForChild("LeftArm")

local rightleg = character:WaitForChild("RightLeg")

local leftleg = character:WaitForChild("LeftLeg")

local hitevent = game:GetService("ReplicatedStorage").re.hit

local damage = 5

local attacking = false

local cooled1 = 1    
ui.InputBegan:Connect(function(input)
    	print("ui input")
    	if input.KeyCode == Enum.KeyCode.Q and attacking == false then 
    		local punchanim = {"Left", "Right"}
    		local chance = math.random(1, #punchanim)
    		print("q")
    		if punchanim[chance] == "Left" then 
    			attacking = true
    			anims.Left:Play()
    			leftarm.Touched:Connect(function(hit)
    				hitevent:FireServer(hit, damage)
    			end)
    			wait(cooled1)
    			attacking = false
    		elseif punchanim[chance] == "Right" then
    			attacking = true
    			anims.Right:Play()
    			rightarm.Touched:Connect(function(hit)
    				hitevent:FireServer(hit, damage)
    			end)
    			wait(cooled1)
    			attacking = false
    		end
    	end
    end)

Did you define “anims”? I don’t see anything defining it unless it was defined outside of the function.

Here’s some things I would recommend:

  1. Remove this line:
if input.UserInputType == Enum.UserInputType.Keyboard then
  1. Make sure a part of the script sets attacking to false.

  2. Check the output. If there are any errors, try to fix them

It was defined outside the function

local character = player:WaitForChild("Character")

local anims = character:WaitForChild("Anims")

It looks like you’re setting attacking to true after the cooldown.

You should be setting it to true before the cooldown and back to false afterward.

Add prints and find where the code breaks. Are you sure that the attacking does = false

#1” and “#2” ??? Please use "Left" and "Right" (or show us your actual code.)

I added prints and ui.InputBegan:Connect(function(input) isn’t even firing

Is this your entire script? First off you never defined UserInputService and you are missing some end for some of your functions

these are my references

local player = script.Parent

local character = player:WaitForChild("Character")

local anims = character:WaitForChild("Anims")

local ui = game:GetService("UserInputService")

local rightarm = character:WaitForChild("RightArm")

local leftarm = character:WaitForChild("LeftArm")

local rightleg = character:WaitForChild("RightLeg")

local leftleg = character:WaitForChild("LeftLeg")

local hitevent = game:GetService("ReplicatedStorage").re.hit

local damage = 5

local attacking = false

local cooled1 = 1

And is there code below the code you showed us in the first post. The original code you showed us is missing 3 end statements.

I edited the original post and now it has the full script

Are you receiving any errors in the Output window?

no nothing even shows up in the output window

Is this a server or client script? Also, where is this script located?

Try Connecting to the Touched Events prior to even calling InputBegan:Connect(),
and within those handlers check for attacking there (and only fire if attacking.)

This is a client script. The script is located under player

Is the script under the Players service? Please be specific when replying.

the script is cloned then the clone is given to the local player

Is the script parented directly to the Player instance?