Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make my gun shoot two times at the same time?

Im making a dual wielding gun tool, but I'm trying to figure out how to make it shoot at the same time. Can someone tell me? CODE:

local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
		local touch, position = workspace:FindPartOnRay(ray, game.Players.LocalPlayer.Character, false, true)
		local trace = Instance.new("Part")
		trace.Anchored = trace
		trace.CanCollide = false
		trace.Transparency = 0.5
		trace.BrickColor = BrickColor.new("Black")
		trace.Material = Enum.Material.SmoothPlastic
		local distance = (tool.Handle.CFrame.p - position).magnitude
		trace.Size = Vector3.new(0, 0, distance)
		trace.CFrame = CFrame.new(tool.Handle.CFrame, position) * CFrame.new(0, 0, -distance / 2)
		trace.Parent = workspace

3 comments

0

note that this code describes how it's going to shoot

0

What exactly are you having trouble with? To make it shoot twice you could just put this in a small for loop.

0

try for i = 1, 2, 1 do (Raycasting code here) end

1 answer

I am assuming you mean shooting two seperate bullets at the same time from TWO SEPERATE guns, just in the same tool(1 tool, a gun model for each arm). What you could do is just copy and paste your code creating the Ray and the visible part. However, you would see both rays in the same spot, so you wouldn’t really see both. You need to create one Ray from a part on the tip of 1 gun all the way to the mouse, and one Ray from the tip of 2 gun to the mouse, and then have the visible part for each Ray. This would essentially be the same code as you have above, just one for each gun model, but in the same tool. Make sense?

This discussion is preserved as it was. New answers, comments, and votes are closed.