Wanting to find out if a player is hit by a lightsaber, but I don't know where to start

So I want to do something where when the player is hit by a lightsaber and isn’t in the safe zone, they lose health, but I don’t know where to start.

Maybe I can use a .Touched event, or Ray-casting (I have no experience with it yet), or something else.

What is the easiest way to do this? Thanks.

You’re spot on! .Touched is the most common method of something like this. Raycasting can be done, too, but would be more complex script-wise.

You can look into how other swords are made if you want. The damage itself looks something like this:

local tool = script.Parent 
local blade = tool.Blade --change to the beam part of the saber 

blade.Touched:Connect(function(hit) 
	local wielder = tool.Parent 
	local target = hit.Parent 
	if wielder ~= target then 
		local human = target:FindFirstChildWhichIsA("Humanoid") 
		if human then 
			human.Health = human.Health - 5 --change this for more/less damage 
		end 
	end 
end) 

You could also implement a “debounce” or delay in damage for something like this, depending on how you want the weapon to function. Your request is a bit broad which is okay since you’re just asking where to start, but if you want a specific answer, you can ask for more specific things.

EDIT: This is just a starting point to work with, and it’s not optimized at all, but instead just meant as a sort of non-optimized template. If you’re completely unfamiliar with coding, you should look into some tutorials or request for more detailed help.

2 Likes

Um, I’m like good I guess? at coding.

What if the player isn’t using the lightsaber and is just moving around?

The way I would go about this is by temporarily enabling the damage each time the tool is activated.

2 Likes

Great, now what about when the player is in the safe zone?

workspace.Safe

Is the safe zone.

So like, how would I find if the player is touching the safe zone?