Designing an FPS Framework: Beginner's guide

Instead of the gun being in my head, it’s inside my arm?

EDIT: I tried anchoring and unanchoring the parts too.
EDIT 2: Now I have problems with the holding animation.
image

Alright i had the same problem too but instead of being in head it was outside the baseplate lol and it seems like you arent sending an animation? Try making animation using moon animator

EDIT : it doesnt matter if the gun is in your hand just animate it and it will work just fine

Can you expain us the reloading procedure it i mean as i see it
You just play an animation and when it ends you have 30 bullets? available?

I am not sure if I am animating it right but I have to go now so feel free to message me on the forum!


What does that line of code do and why do we need part in viewmodel called camerabone?

That line is for returning the Part0’s position to its normal position by adding the inversed CFrame of the part0 and the part1’s CFrame. The camera bone is for future camera animations.

Is the Part0 the Handle or v? I read somewhere that when you multiply the inverse of a CFrame by another CFrame it is similar to dividing, is that true?

Well Part0 is the handle of course, and I think it’s similar to v3 + -v3. Correct me on this one if I’m wrong.

In this case when you do v3 + -v3 it gives you the normal position of Part0?

Not really since I’m pretty sure C0 has something to do with relative offsets and CFrames are much different than Vector3s.

So it offsets the handle relative to Newmotor.Part1.CFrame?

I still find that line very confusing.

1 Like

This is about the animations. After I copy the viewmodel with the gun, I add the viewmodel into moon animator and Roblox Studio crashes.

1 Like

I also have a problem with the gun. If I am standing close to an object the part shoots to my left.

1 Like

This is happening to me help, please

When I shoot my gun. Continues shooting even if I’m not holding the mouse button 1

Please provide the code that you’re currently using.

It sadly is late for me so I’m not at my computer but I’ll update u I’m the morning

Idk jf
It is my mouse that does not work but it does work for other games

I’m online now The code i am using is

local module = {}
function module.update(viewmodel, dt)
	viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame
end

function module.weldgun(gun)
	local Main = gun.GunComponents.Handle
	
	for i, v in pairs(gun:GetDescendants()) do
		if v:IsA("BasePart") and v ~= Main then
			local NewMotor = Instance.new("Motor6D")
			NewMotor.Name = v.Name
			NewMotor.Part0 = Main
			NewMotor.Part1 = v
			NewMotor.C0 = NewMotor.Part0.CFrame:Inverse() * NewMotor.Part1.CFrame
			NewMotor.Parent = Main
		end
	end
end
function module.equip(viewmodel, gun, hold)
	local GunHandle = gun.GunComponents.Handle
	local HRP_Motor6d = viewmodel:WaitForChild("HumanoidRootPart").Handle
	
	gun.Parent = viewmodel
	HRP_Motor6d.Part1 = GunHandle
	HRP_Motor6d.Part0 = viewmodel.HumanoidRootPart
	local Hold = viewmodel.AnimationController:LoadAnimation(hold)
	Hold:Play()
end

function module.cast(gun, endposition, velocity)
	local GunBarrel = gun.GunComponents.Barrel
	local Bullet = Instance.new("Part")
	Bullet.Size = Vector3.new(1, 1, 5)
	Bullet.Anchored = true
	Bullet.CanCollide = false
	Bullet.Color = Color3.new(0.999084, 0.947265, 0.604257)
	Bullet.Material = Enum.Material.Neon
	Bullet.Parent = game.Workspace
	
	Bullet.CFrame = CFrame.new(GunBarrel.Position, endposition)
	
	Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
		Bullet.CFrame *= CFrame.new(0, 0, -velocity * dt)
		if (Bullet.Position - GunBarrel.Position).magnitude > 5000 then
			Bullet:Destroy()
			Loop:Disconnect()
		end
	end)
	
	
end

return module

The local Handler

local GunModel = game.ReplicatedStorage:WaitForChild("Groza")
local ViewModel = game.ReplicatedStorage:WaitForChild("Viewmodel")
local AnimationsFolder = game.ReplicatedStorage:WaitForChild("Groza_Animations")
--main module thing
local MainModule = require(game.ReplicatedStorage.MainModule)
ViewModel.Parent = game.Workspace.Camera


game:GetService("RunService").RenderStepped:Connect(function(dt)
	MainModule.update(ViewModel, dt)
end)

MainModule.weldgun(GunModel)
MainModule.equip(ViewModel, GunModel, AnimationsFolder.Hold)

local IsPlayerHoldingMouse
local CanFire = true
local Delay = 0.1

game:GetService("RunService").Heartbeat:Connect(function(dt)
	if IsPlayerHoldingMouse then
		if CanFire then
			CanFire = false
			
			MainModule.cast(GunModel, game.Players.LocalPlayer:GetMouse().Hit.Position, 60)
			
			wait(Delay)
			CanFire = true
			
		end
	end
end)

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		IsPlayerHoldingMouse = true
	end
end)
game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		IsPlayerHoldingMouse = false
	end
end)

Edit: Never mind i understood my mistake i put Input began when it was suppose to be inputEnded

image
Both of these events are InputBegan. Make the one at the bottom InputEnded