Trying To Make a Shotgun Version Of My Gun System

Hello! So Today I Am Making a Game Based Off a Hood/Reallife Game On Roblox, So I Have a Question.
How Do I Make a Shotgun Burst On My Gun ? Im Trying To Make It Everytime It Fire’s, It Has 5 Ray’s Coming Out Of The Weapon’s Barrel And Also Burst So It Doesnt Go In 1 Direction Only.
The Code Is Below :

Handler

local character
local humanoid
local animator
local animate
local animate2
local equipped = false
local filterArray = {}
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

damage = 17

script.Parent.RequestFire.OnServerEvent:Connect(function(plr,targetPosition)
	if script.Parent:FindFirstChild("Handle") and equipped == true then
		if animate2 then
			animate2:Stop()
		end
		animate2 = animator:LoadAnimation(script.Fire)
		animate2:Play()
		
		local spreadPosition = targetPosition + Vector3.new(math.random(-500,500)/1250,math.random(-500,500)/1250,math.random(-500,500)/1250)
		
		local raycastResult = workspace:Raycast(
			(script.Parent.Handle.CFrame * CFrame.new(-1.9,0.11,0)).Position,
			(spreadPosition - (script.Parent.Handle.CFrame * CFrame.new(-1.9,0.11,0)).Position).Unit*500,
			raycastParams)

		if raycastResult then
			local partHit = raycastResult.Instance
			if partHit.Parent:FindFirstChild("Humanoid") then
				if partHit.Parent.Humanoid.Health > 0 then
					if partHit.Name == "Head" then
						partHit.Parent.Humanoid:TakeDamage(damage*2.5)
					else
						partHit.Parent.Humanoid:TakeDamage(damage)
					end
					if partHit.Parent:FindFirstChild("Burn") == nil then
						local burn = script.Burn:Clone()
						burn.Parent = partHit.Parent
						burn.Disabled = false
					else
						partHit.Parent:FindFirstChild("Burn").BurningTime.Value = partHit.Parent:FindFirstChild("Burn").BurningTime.Value + 2
					end
				end
			elseif partHit.Parent:IsA("Accessory") then
				for _, ins in pairs(partHit.Parent.Parent:GetChildren()) do
					if ins:IsA("Accessory") then
						table.insert(filterArray,ins)
					end
				end
				raycastParams.FilterDescendantsInstances = filterArray
			end
		end
		coroutine.wrap(function()
			script.Parent.Handle.PointLight.Enabled = true
			script.Parent.Handle.BillboardGui.Enabled = true
			script.Parent.Rpart.FlashGui.Enabled = true
			wait(.08)
			script.Parent.Handle.PointLight.Enabled = false
			script.Parent.Handle.BillboardGui.Enabled = false
			script.Parent.Rpart.FlashGui.Enabled = false
		end)()
		local trailPart = Instance.new("Part",workspace)
		trailPart.Name = "TrailPart"
		trailPart.Transparency = 1
		trailPart.CanCollide = false
		trailPart.Anchored = true
		local attachment1 = Instance.new("Attachment",trailPart)
		local beam = Instance.new("Beam",trailPart)
		game.Debris:AddItem(attachment1,.075)
		game.Debris:AddItem(trailPart,.075)
		attachment1.WorldPosition = spreadPosition
		beam.Color = ColorSequence.new(Color3.fromRGB(243, 255, 8),Color3.fromRGB(251, 255, 0))
		beam.LightEmission = 1
		beam.LightInfluence = 0
		beam.Transparency = NumberSequence.new(0,1)
		beam.Attachment0 = script.Parent.Handle.BarrelAttachment
		beam.Attachment1 = attachment1
		beam.FaceCamera = true
		beam.Width0 = 0.100
		beam.Width1 = 0.100
		script.Parent.Handle.Fire1.PlaybackSpeed = 1 + math.random(-100,100)/1000
		script.Parent.Handle.Fire1:Play()
		script.Parent.Handle.Fire2.PlaybackSpeed = 1 + math.random(-100,100)/250
		script.Parent.Handle.Fire2:Play()
	end
end)
script.Parent.Activated:Connect(function()
	script.Parent.Activated:Connect(function()
		for _, ins in pairs(workspace:GetChildren()) do
			if ins:FindFirstChild("Humanoid") then
				for _, ins2 in pairs(ins:GetChildren()) do
					if ins2:IsA("Accessory") then
						if table.find(filterArray,ins2) == nil then
							table.insert(filterArray,ins2)
						end
					end
				end
			end
		end
		raycastParams.FilterDescendantsInstances = filterArray
	end)
end)
script.Parent.Equipped:Connect(function()
	equipped = true
	character = script.Parent.Parent
	if table.find(filterArray,script.Parent.Parent) == nil then
		table.insert(filterArray,script.Parent.Parent)
	end
	if table.find(filterArray,script.Parent) == nil then
		table.insert(filterArray,script.Parent)
	end
	raycastParams.FilterDescendantsInstances = filterArray
	if character then
		humanoid = character.Humanoid
		if humanoid:FindFirstChild("Animator") == nil then
			animator = Instance.new("Animator",humanoid)
		elseif humanoid:FindFirstChild("Animator") then
			animator = humanoid:FindFirstChild("Animator")
		end
	end
	animate = animator:LoadAnimation(script.Hold)
	animate:Play()
end)
script.Parent.Unequipped:Connect(function()
	equipped = false
	if script.Parent:FindFirstChild("Handle") then
		script.Parent.Handle.PointLight.Enabled = false
		script.Parent.Handle.BillboardGui.Enabled = false
	end
	for _, ins in pairs(script.Parent.Handle:GetChildren()) do
		if ins:IsA("Sound") then
			ins:Stop()
		elseif ins:IsA("PointLight") then
			ins.Enabled = false
		end
	end
	if animate then
		animate:Stop()
	end
	if animate2 then
		animate2:Stop()
	end
end)

LocalHandler

local mouse = game.Players.LocalPlayer:GetMouse()
local equipped = false
local connection
local connection2
local active = false
local debounce = false
local isSemi = true

script.Parent.Equipped:Connect(function()
	equipped = true
	connection = mouse.Button1Down:Connect(function()
		if equipped == true and debounce == false then
			local Old = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 4
			wait(0.01)
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
			if isSemi == false then
				active = true
				repeat
					if debounce == false then
						debounce = true
						local mousePos = mouse.Hit.Position
						script.Parent.RequestFire:FireServer(mousePos)
					end
					wait(3)
					debounce = false
				until active == false
			elseif isSemi == true then
				if debounce == false then
					debounce = true
					local mousePos = mouse.Hit.Position
					script.Parent.RequestFire:FireServer(mousePos)
					wait(0.3) ----------- Changing CoolDown Each Shot
					debounce = false
				end
			end

		end
	end)
	connection2 = mouse.Button1Up:Connect(function()
		if equipped == true then
			active = false
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 4
			wait(0.5)
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
		end
	end)
end)
script.Parent.Unequipped:Connect(function()
	equipped = false
	active = false
	connection:Disconnect()
	connection2:Disconnect()
end)

If Anyone Could Help Please Reply, I Need This For My Game

Pls Help Me I Really Need This

is there an error? have you tried the code?

Actually i tried making a shotgun, all i have to do is just to duplicate the ray but idk how

Hey, im sorry, but i was caught up in a lot of rl problems. So i know im late, and you have most likely figured it out, but basically to add spread you would multiply ray direction but a random number, and you could use a module to sort out ray clones and not have to copy paste in every script.

1 Like

I’ve already figured it out like days ago. I appreciate your reply so have a nice day :slight_smile: