Lightsaber combat system

Hello! I am currently creating a star wars type game and am not really sure how to make a combat system for lightsabers. I am quite inexperienced with combat systems with guns, melees, etc. I hope to get a better understanding for how they work.


Hey! I am here to help you. There are many different styles of combat that you can implement here.

  1. Damage when light saber touch a model: Attaching script to the light saber to detect a model when it swings.
  2. Damage when click a model: This is like a old-fashioned MMORPG game, that you damage other players by simply clicking on them.

Yes, I know that I need to detect a model. I’m just not sure if I should use raycasting or something else.

Raycasting will come into play when you want to create guns, or any ranged weapons. For melee weapons, you can simply use Touched() event to detect if your weapon detects anything. In case that you want to create a ranged weapon, Roblox website provide a full tutorial on how to make one.

I’ve tried it. It can be really buggy and laggy. I’ve looked at other posts for melee and have seen raycasting as a popular method for combat systems in general.

Do you still have the code? If so, you can post it here and we can help you on how the code can be optimized. And yes of course, you can also use raycasting method on melee weapon. Here is my approach, when the tool on your hand is activated, you can simply cast a ray from your HumanoidRootPart forward and see if it detects other players model.

Alright, thanks! I can’t do it now but I will reach out with any additional questions.


If I use raycasting how should I time the ray. Also, if I use Touched() should I add some sort of hitbox?

You will cast a new ray when Tool:Activated() is being called. For this approach, you will need to manually check how long your ray should be based on the range of your weapons (Dagger will have short range, and sword will have a longer range.) If you want to use ray cast, you may create an invisible part in front of the player using WeldConstraint and Attachment. Then cast a ray from your humanoid to that part

If you want to use Touched() You can see the property of CanTouch inside your weapon to true. After that, when Tool:Activated() is called, you can swing your weapon, and see if your weapon touches other player’s humanoid.

Yeah I understand how these functions work. I was just wondering if I use raycasts, I just don’t understand how to time them because I don’t want them to get damaged before the hit. Thanks for the help, I appreciate it.

No problem! And if my post does help you, please mark one of my posts as a solution. Thank you very much!


Yeah, I will. I’m just not sure how to time the raycasts if I use the raycast method.

This has many approaches you can use, it depends on how you animate your character when the tool is activated. For simplicity purposes, I will separate it into 3 ways that you can achieve this.

  1. Cast right away after the tool is activated: After using Tool:Activated() you can cast the ray right away, this will work just fine if your animation for swinging weapon last like 1 second. The player won’t be able to notice that the damage has already been calculated because it is too fast. The problem for this approach is that if the player 1 hits player 2 and flick fast before the animation ends, player 2 will think that player 1 is cheating because the sword doesn’t hit him but the damage has already been calculated.

  2. Cast right after the animation is done: Same thing as the first one, but you cast the ray before the function ends. The main difference is just only the order of your code. the problem is that if player 1 doesn’t look at player 2 the whole time when slash, that hit will be considered as miss.

  3. Time it right when your weapon hits other: If you make your animation yourself, you can use delay() to tell the function when it should cast the ray based on how long your animation is. This is probably going to be a little bit time-consuming, but your weapon will slash others when it should.

1 Like

Thanks! I will mark this as a solution.


Thank you very much! I’m glad I could help! Enjoy coding!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.