How to achieve this gun system

So, i play a game named The Hunt a lot, its a pretty cool game inspired by isle, and in it theres a customized gun system thats pretty cool, basically when u click on a exact enemy u point a red laser to the enemy,

and after 3 second u shoot a amount of bullets, like 1 for a pistol, 3 for a M4A1 so it isnt op,
and it has short amount of bullets like 36 for M4A1,

And when the enemy goes behind a wall it stops the waiting to shoot and the laser
Can anyone help me doing that?

2 Likes

Fire a ray from the point on the gun you want in the directions of the laser emits look Vector.

A ray is basically a invisible line that will tell you if it struck any part then return the position it struck and the part instance itself.

2 Likes

I have made a LaserGun (My Laser Gun) , I don’t think it’s what you are asking for but you can take the scripts of my gun to make your system…

1 Like

uhm what do you mean by that? i didnt understand it…

1 Like

Oh thx! i will check it later!

This is 100% the best way to do it. Since @TruckDriv3r didn’t understand, I’ll link some documentation on ray casting: Raycasting | Roblox Creator Documentation

Here is a little code snippet I made for a gun system like the one you want to create. I recommend putting the ray cast function inside of a module script btw.

if raycastResult then
	if raycastResult.Instance.Parent:FindFirstChild("Humanoid") then
		raycastResult.Instance.Parent.Humanoid.Health = 0

		print(raycastResult.Instance.Parent.Name.." Has been killed!")
	end
end

This is just a bare bones if statement for a ray casting gun, and should be treated as an example, not code you should copy and paste into your script, it might not even work because of a few typos, just use it as an example when making your script.

Oh i will check that later too, thx!

Oh thx! actually its not that hard!

1 Like