I know most people say to weld the model to the roblox characters right arm or something like that but can anyone point me to a decent example of how to accomplish a custom weapon system found in phantom forces, mad paintball and other games?

wait()
--services
local lighting = game:GetService("Lighting")
local serverstorage = game:GetService("ServerStorage")
local workspace = game:GetService("Workspace")
-- variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character
local torso = script.Parent.Torso
local gun = lighting.Models:FindFirstChild("AR15")
local gun2
local main
local cam = game.Workspace.CurrentCamera
local sprint = true
local walk = true
--functions
	local function weldBetween(a, b)
    local weld = Instance.new("ManualWeld", a)
    weld.Part0 = a
    weld.Part1 = b
    weld.C0 = a.CFrame:inverse() * b.CFrame
    return weld
	end
	
	function wepCreate()
		local a = gun:Clone()
		a.Main.CanCollide = false
		local b = gun:FindFirstChild("Main")
		a.Parent = character
		b.CFrame = CFrame.new(torso.Position + Vector3.new(-0.5, 0, -3))
		weldBetween(gun.Main, torso)
		b.CFrame = CFrame.new(torso.Position + Vector3.new(-0.5, 0, -3))
		gun2 = a
		main = gun2:FindFirstChild("Main")
		a.Main.Anchored = false
	end
	

	function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
		print("Reloading")
		end
	end
 
	game:GetService("UserInputService").InputBegan:connect(onKeyPress)	
	-- shooting
	mouse.Button1Down:connect(function()
		print("Mouse pressed!")
		local ray = Ray.new(main.CFrame.p, (mouse.Hit.p - main.CFrame.p).unit * 300)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
 
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("Black")
		beam.FormFactor = "Custom"
		beam.Material = "Plastic"
		beam.Shape = "Ball"
		beam.TopSurface = "Smooth"
		beam.BottomSurface = "Smooth"
		beam.Anchored = false
		beam.Locked = true
		beam.CanCollide = false
 		local f = Instance.new("Fire", beam)
		local distance = 50
		beam.Size = Vector3.new(1, 1, 1)
		local d = Instance.new("BodyVelocity", beam)
		d.Velocity = character.Head.CFrame.lookVector * (225)
		beam.CFrame = CFrame.new(main.CFrame.p)
 
		game:GetService("Debris"):AddItem(beam, 3)
 
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
 
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
 
			if humanoid then
				humanoid:TakeDamage(30)
			end
		end
	end)
	
	--ads
	mouse.Button2Down:connect(function()
		if sprint == false then
		if cam.FieldOfView == 70 then
			cam.FieldOfView = 50
		else
			cam.FieldOfView = 70
		end
			else
		end
	end)
	
	mouse.Button2Up:connect(function()
		if cam.FieldOfView ~= 70 then
		cam.FieldOfView = 70
		else
			end
	end)

I have this script here that I wrote but it has lots of issues with it I was wondering if somebody could help

1 comment

0

I would weld it to the arm, then make some animations.