How do I make a gun?

Hi. I want to know how to make a tool where if I click somewhere a beam appears for a few seconds where I clicked. But I don’t know how to make one. Can somebody guide me through? I want to make it so the beam comes out of a attachment with a specific name. Thanks

oo, matrix transformation math :woozy_face: u basically have a vector which you are trying to align the part by. a vector can be formed by 2 points and those 2 points is your attachment u shooting it out of and your mouse’s projected world space position (mouse.Hit.Position). what u gotta do basically is apply a lookat matrix, roblox does this easy for us with CFrame.lookAt(eye, target). so apply that matrix transformation then you need to align it. Because of how roblox renders objects, if a object is at origin and you scale it on the z by say 10 it will scale evenly on both sides. so what u gotta do is basically put the object in the center and then since if we scaled it by 10 it moves by like 5 on both sides, so basically it is the vectors length / 2, cause they scale evenly.

1 Like

2 words: Youtube. Tutorials.
i suggest you use dev fourem as a last resort
anyways I just typed beam gun on yt and this seems helpful

If you have at least a bit of scripting knowledge, you could implement this pseudocode very quickly (which I think I used at one point)

Mouse.Hit.Position
Get Position of end of gun
Size.Z is distance
Part rotation is LookVector of GunPos to HitPos
Add to debris service with time in seconds

it’s a bit more involved than that, but here is a little sample of what i was talkin about

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
	local curMouse = game.Players.LocalPlayer:GetMouse()
	local part = Instance.new("Part")
	part.Anchored = true
	part.CanCollide = false
	local vec = curMouse.Hit.Position - script.Parent.Head.Position
	part.CFrame = CFrame.new(Vector3.new(curMouse.Hit.Position + vec*0.5) + vec*0.5) * CFrame.lookAt(script.Parent.Head.Position, curMouse.Hit.Position)
	part.Size = Vector3.new(0.1, 0.1, vec.Magnitude)
	part.Parent = workspace
end)

~~
simplified the math in math papa the position is just the vectors tail + the vector
so it seems that simplfying vector math isnt the same as algebra, it didnt work. it’s basically the position between half of the vectors, expresssed with the ray point formula then just a offset of half of it

thats literally what i wrote down lol, forgot to say you need to set the position to the average of the two vectors though.

hm, well the thing i wrote still works. i guess it just does the same thing with extra steps?? who knows

What I wrote was pseudocode, which is basically just an outline of code. It’s incredibly useful when figuring out how to approach a problem, especially the more complex it gets, and I find myself using it more often the more complicated my projects get.

question. ive heard people stay pseudo alot of times in the dev forum. what does it mean. and also thanks ill try the script

it means like its not actual code but rather what to do in your code, almost like an outline

1 Like

Pseudo itself means “kind-of”, as in “not really”. See post above yours:

1 Like

Step 1: Open Toolbox

Step 2: Take the free model gun by Roblox

Step 3: Duplicate and change the gun model to your own model

Step 4: Profit

Pick Auto Rifle

Copy this, remove the mesh ID and set Transparency to 1

Get new gun model, select all grouped parts, press Ctrl+Shift+W to weld it all together


Clone Tool, delete old Model, insert new Model into Tool

Move Model to align with Handle, then add Rifle as PrimaryPart to Model

Select a part inside model and weld it to Handle (Ctrl_Shift+W)

Realign Attachments inside Rifle, Disable MuzzleFlash Beam after that

image

You got a gun!

Final Steps
Search for WeaponsSystem Module,
Change this line
image
(Ctrl+G, then input 185)

To this
image

Next, go to Line 368 - 382 (Ctrl+Shift+G, put in 368)
And change it to this

Finally, go to ShoulderCamera Module Script
Go to line 276 - 280
Change it to this

And you’re done!

2 Likes