Help with hitbox system!

Apologies for the messy script. I’m new to scripting and don’t know what render stepped is. please help

Because they need to be constantly cloned when swinging in order to have a more accurate hit.

that’s where the docs will become real helpful.
RenderStepped is an event that’s pretty much called every time a new frame is rendered (don’t know the exact part of the rendering process that it’s called but it’s something like that)

1 Like

How is this typed out in my localscript?

1 Like

At the start of the script you’ll need to get RunService. Based on your code you should know how to do this

Then just connect the RenderStepped event to a function.

For example

runservice.RenderStepped:Connect(function()
-- this will run every single frame
end)
1 Like

when you say “This will run every single frame” do you mean it’ll clone every single hitbox? or…

whatever code you put inside the event will run every single event. for example

runservice.RenderStepped:Connect(function()
  print("hello")
end)

would print hello every single frame.

1 Like

for this, how would I know how many frames there are?

I’m just not sure how to implement this into my code either :confused:

You could keep a counter variable to keep track of how much frames have passed

local frames = 0

rs.RenderStepped:Connect(function()
  frames += 1
  print(frames.." frames have passed!")
end)

Also, I’m not sure of what you wanted to achieve in the beginning, I just saw the most recent comment from you asking about how RenderStepped worked so I just came in to explain that. Sorry about that.

What do you mean more accurate? If you weld the hitbox to the sword then it would follow the sword wherever it goes with basically no delay

1 Like

I agree with him. Welding a part to the sword seems the best approach.

1 Like

Where is the code that does damage? Looks like your hitboxes are empty you must connect a function like:

Hitbox1Clone.Touched:Connect(doesDamage)

You must remove this:

		Hitbox1Clone.CanTouch = false
		Hitbox2Clone.CanTouch = false

I make it create mutliple hitboxes so it could hit multiple people at the same time during a swing. and also having more frequent hitboxes has more touch accuracy.

I think you may want to use this raycast hitbox for your melee attacks. It works by constantly (and effeciently) raycasting between where a hitbox is and where it was one step ago. This prevents the need to constantly spam hitboxes for them to be accurate to where the sword is.

BasePart.Touched:Connect() is unreliable and buggy. Only ever use it if you need to check when a part is touched, not when it is inside something.

3 Likes

I can vouch for what @TheCraftNCreator suggested. I have used it in the past, and it is a really good module.

You are absolutely right, thank you for telling me.

Why not use the Raycast Hitbox 4.01 module? I personally use that module when creating melees because…

  1. Hitboxes can ignore the player using the melee
  2. The hitbox is extremely accurate (due to using ray casting and not parts)
  3. The hitbox is reliable (it will keep working and not break)
  4. The hitbox will only damage a player once, and can detect and damage multiple players at once
  5. Way easier to program and implement onto melees than creating hitboxes using parts

Which just so happens to fix all of the problems you are facing right now so I would highly recommend that you check it out!

(Seems like @TheCraftNCreator has already mentioned it, but it just shows how amazing the module is when creating melee weapons)

1 Like

Thanks for replying! The thing is, is that I’ve used this before and it causes lag, so inaccurate (it hit someone super far away from me), and can’t figure out a way to make a localized way to show and not show the rays.

Lag? Were you running it serverside?