User:Tenal/How to script laser guns

From Legacy Roblox Wiki
Jump to navigationJump to search

Ever since Vortex Security's debut and clan growth in late 2010, many clans and game developers alike started using laser weapons instead of projectiles for use in their places. This guide will instruct you step-by-step in laser gun creation.

It is important to know that the term "raycasting guns" used by many people is false. Raycasting is an algorithm, not a type of gun. Also, just because a weapon has flashy and pleasing effects doesn't mean the scripting difficulty in it is advanced. Saying "high-tech gun" can be said in terms of roleplay, but "advanced scripted gun" would not make sense.

Building the gun

Minimapped pistol with multiple parts.

You can build the gun in any way you want. Using a bunch of parts and minimapping them is fine; so is getting a gun mesh and optionally retexturing that. Keep in mind that in the scripting section of this tutorial we're going to imply that you're using a multiple-part gun and that the handle and the gun barrel would be two separate parts.

Scripting the gun

Scripting the laser gun is what this tutorial is all about. So, we are going to split it in multiple parts.

Making the gun shoot on mouse click

In this section of scripting, we will use the following events/methods:

Button1Down ( )
Description Fired when the mouse is in the left mouse down state.
Member of: Mouse





FindPartOnRay( Ray ray, Instance ignoreDescendentsInstance, Bool TerrainCellsAreCubes )
Returns BasePart object, Vector3 position
Description: Returns the first part that intersects with a ray.
Member of: Workspace