Designing an FPS Framework: Beginner's guide

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

I use your code and models, follow your tutorial from a to z. But the arm DIDN’T show up and so did the gun. Can you send me an uncopylocked place that include everything you show?

Hey, I need help, I keep getting this error:Handle is not a valid member of MeshPart “Workspace.Camera.Viewmodel.HumanoidRootPart”

Here are my scripts:

Local Handler

repeat wait() until game:IsLoaded()

local GunModel = game.ReplicatedStorage:WaitForChild("Groza") -- your gun
local ViewModel = game.ReplicatedStorage:WaitForChild("Viewmodel") -- the viewmodel!!

-- our main module
local MainModule = require(game.ReplicatedStorage.MainModule)

ViewModel.Parent = game.Workspace.Camera
GunModel.Parent = ViewModel
MainModule.weldgun(GunModel)

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

MainModule.equip(ViewModel, GunModel)

MainModule:


local module = {}

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

function module.weldgun(gun)
	local Main = gun.GunComponents.Handle
	print("1")
	local d
	for i, v in ipairs(gun:GetDescendants()) do
		print("2")
		if v:IsA("BasePart") and v ~= Main then
				print("3")
				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
	print("4")
end

function module.equip(viewmodel, gun)
	local GunHandle = gun.GunComponents.Handle
	local HRP_Motor6D = viewmodel:WaitForChild("HumanoidRootPart").Handle
	
	gun.Parent = viewmodel
	HRP_Motor6D.Part1 = GunHandle
end

return module

One question, if I wanted to have multiple different weapons, would I just put the handler in the gun and move it to the player when the gun is needed?

Make sure the Motor6D are in place correctly

I wouldn’t recommend it, instead just have 1 handler or module if you want to. and switch between guns there (remove the handle weld p1 and reattaching to the new gun (and possible change the settings like damage as well))

1 Like

I think better to use:

game:GetService("Debris"):AddItem(Bullet,LifeTime)

Not necessarily, if your bullet travels slowly it can be problem. So it’s better to check for distance.

Unsure what I am doing wrong here but the gun doesnt appear in head (up to stage where Ive got equip/weld/update all setup) and im using same gun model and viewmodel. Unsure if it’ll affect animating in the future


image


local Framework = {}

function Framework.Update(viewModel, deltaTime)
	viewModel.HumanoidRootPart.CFrame = workspace.CurrentCamera.CFrame
end

function Framework.WeldGun(gun)
	local Handle = gun.Components.Handle
	
	for i, v in ipairs(gun:GetDescendants()) do
		if v:IsA("BasePart") and v ~= Handle then
			
			local NewMotor = Instance.new("Motor6D")
			NewMotor.Name = v.Name
			NewMotor.Part0 = Handle
			NewMotor.Part1 = v
			NewMotor.C0 = NewMotor.Part0.CFrame:Inverse() * NewMotor.Part1.CFrame
			NewMotor.Parent = Handle
		end
	end
end

function Framework.Equip(viewModel, gun)
	local Handle = gun.Components.Handle
	local HumanoidRootPartMotor = viewModel:WaitForChild("HumanoidRootPart").Handle
	
	gun.Parent = viewModel
	HumanoidRootPartMotor.Part1 = Handle
end



return Framework
local GunModel = game.ReplicatedStorage:WaitForChild("Gun"):Clone()
local ViewModel = game.ReplicatedStorage:WaitForChild("ViewModel"):Clone()

local Framework = require(game.ReplicatedStorage.Framework)

ViewModel.Parent = workspace.CurrentCamera
Framework.WeldGun(GunModel)

game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
	Framework.Update(ViewModel, deltaTime)
end)

Framework.Equip(ViewModel, GunModel)
1 Like

I’m pretty sure there’s something wrong with the welding or the gun model, or maybe even the viewmodel itself, but there will technically be no problem with animating it (other than its weird to animate the gun like that and a possibility of it randomly fixing itself in the future and breaking the animation).

Hi, are you able to make the animation free or give file to re upload?

Woah! Nice tutorial! I’ll definitely use this in the future.

Also I have a smol question, what font do you use?

mate just gotta say that this is one of the easiest to understand tutorial about fps frameworks cause some involves tons of math which they don’t explain and I don’t understand lol but yours it’s pretty self explanatory definitely helps me thanks

took my a while to find it

6751862322.rbxm (1.3 KB)

pretty sure this is the right one

1 Like

Why isn’t my hold animation working?

2 Likes

So when I test, the gun is parented to my viewmodel, but it is invisible and when I move, the gun doesnt move someone pls help

How would I make the framework show to the other clients? as an example, you can see other players holding their guns on Phantom Forces.

Simply send a signal to the server to display the server side model of the gun

Check the position of the gun, make sure it’s updating to the camera’s position. The problem can also come from the viewmodel itself or the welding.

Well yeah I know that but theres a problem, the original viewmodel is parented to the Camera, which makes me have a few problems and question:

How would I go about making the viewmodel visible to other people in an optimizedand good way?

Theres a few options I thought of but they all seem to have problems, like:

  • Sending the CFrame to the server to update (would make 2 viewmodels appear to the original client and maybe would be laggy as its a remote event sent every render stepped)

  • Doing the previous option but instead of updating on the server, update on each client that aint the original (probably way more laggy than the first option, but atleast solves the 2 viewmodels problem)