How does click combat work?

I dont really have code for click combat, (and i don’t want code from anyone, i wanna try to understand and learn how it works. Examples of code are fine tho!!!)

I dont really understand how click combat works, i want to make a game with click combat. An exclamation of how it works would be appreciated, thank you for your time :grinning:

1 Like

If you mean where you click and then attack.

  1. Use UserInputService to detect clicks from player
  2. Make a debounce variable so player can’t spam attack
  3. When player clicks check if debounce (cooldown) is true or false
  4. If debounce is false then load and play your attack animation and spawn a hitbox
  5. Detect what is touching or inside of the hitbox, which will most likely return a table of parts in most methods
  6. Check if those parts in the table are apart of a character
  7. If they are you can apply damage to the Humanoid of the character using Humanoid:TakeDamage()

Let me know if you need any clarification on any of the steps or examples of what I mean.

2 Likes

How to make a tool do something when a player clicks -

function Activated()
-- code here
end

script.Parent.Activated:Connect(Activated)
2 Likes

Im not so sure what a hitbox is, or how they work. Could you please elaborate?

Thank you alot! im not really fond of tools tho, but i appreciate the code sample

Hitboxes are invisible boxes that are used for detecting collisions more efficiently than parts with meshes, custom shapes, etc. They generally don’t have collisions of their own, mostly in the situation being described here.

2 Likes

But wouldnt this work only twice? what i mean is, i’d only be able to do two punches. What if i wanted to have a max of 4 or 5?

would i create one by using instance.new()?

There isn’t a hitbox Object, but instead you’d spawn a part covering the areas where you want collisions to be for said attack, and check the collisions there.

2 Likes

for example code, you can say:

-- The UserInputService happenned


local Hitbox = Instance.new("Part")
Hitbox.Size = -- Whatever box sized hitbox you want
Hitbox.Shape = enum.Shape.Block -- just confirm its a block

Hitbox.Touched:Connect(function(hit)
   local Check = hit.Parent:FindFirstChild("Humanoid")  -- Check if it's  a character
   
   if Check then
         Check:TakeDamage(100) -- Damage the humanoid

   end)
end)

If you have questions about the code you can ask. (it can be a bit confusing)

3 Likes

Would i make the hitbot the same size as the part i want to hit?

Nope! You just have to make the size as big as you want! basically the bigger the numbers the bigger the chance of hitting the player : )

also remember that the size value is a tuple like this (0,0,0) and for better calculations you may want to make your hitbox ahve the same numbers such as (5,5,5)

2 Likes

Thank you so much!!

im not so sure what id put on the user input, but i have an idea

would it all be client sided or local?

UserInput is all local, I would recommend reading up on that more under the API Doc. UserInputService

2 Likes

where would i parent the hitbox?

The Characters’ HumanoidRootPart, thats the best place to for this scenario

1 Like

So i wrote this script,

mouse.Button1Down:Connect(function()
	if not DBounce then
		DBounce = true
		punch1Track:Play()
		wait(waitTime)
		DBounce = false
	elseif DBounce then
		DBounce = true
		punch2Track:Play()
		wait(waitTime)
		DBounce = false
	end
end)

(the wait time is 5 seconds)

but the result wasnt what i wanted

is there anything wrong with my code?

1 Like

Instead of putting them in the same function, you can separate them thru InputStarted, which can help with your variable organization. For this you could do:

UserInputService.InputBegan:Connect(function(Input)
   if Input.UserInputType == Enum.UserInputType.MouseButton1 and not Dbounce then
        DBounce = true
        punch1Track:Play()
        wait(waitTIme)
        DBounce = false
   end
end)
2 Likes

would i copy the same code but change the Debounce and animations?