Designing an FPS Framework: Beginner’s guide [PART 2]

Hey! I just tested your script and it seems to work fine for me, If the problem is still there, can you please provide a video showing this. Thanks!

1 Like

here is the video showing that it just snaps to the position

1 Like

That’s weird, I’ve copied the code you gave and it works fine. Try and debug your code. (print the AimAlpha’s value) or check the value ingame. I’ve also provided the source code for you to compare with your own.

https://devforum.roblox.com/uploads/short-url/oCSN40s0y5IzgGQo7MkGS3ecADd.rbxm

my code is exactly the same as the source code yet doesnt do it i printed the aimalpha’s value and its correct (0 when not aiming, 1 when aiming)

The value should smoothly transition from 0 to 1. Not snapping 0 to 1 directly.

the tweening in the script is the same as the tweening in the source code yet it snaps

mine:

function module.aim(toaim, viewmodel, gun)
	if toaim then
		game:GetService("TweenService"):Create(game.ReplicatedStorage.Values.AimAlpha, TweenInfo.new(1), { Value = 1 }):Play()
	else
		game:GetService("TweenService"):Create(game.ReplicatedStorage.Values.AimAlpha, TweenInfo.new(1), { Value = 0 }):Play()
	end
end

source:

function module.aim(toaim, viewmodel, gun)
    if toaim then
        game:GetService("TweenService"):Create(game.ReplicatedStorage.Values.AimAlpha, TweenInfo.new(1), { Value = 1 }):Play()
    else
        game:GetService("TweenService"):Create(game.ReplicatedStorage.Values.AimAlpha, TweenInfo.new(1), { Value = 0 }):Play()
    end
end

Try comparing the local handler, if the module is fine maybe it’s from the local handler. If that doesn’t work try and copy pasting the original local handler and connect it to your module.

its the same it calls for

module.aim(true, viewmodel, gunmodel) 

or

module.aim(false, viewmodel, gunmodel)

vars:

local gunmodel = game.ReplicatedStorage:WaitForChild("Weapons"):WaitForChild("Groza")
local viewmodel = game.ReplicatedStorage:WaitForChild("Viewmodel")

copy and pasting it doesnt do anything

Well then, can you provide the entire local handler code?

im using fastcast so some of the firing is different

game:GetService("UserInputService").MouseIconEnabled = false
--guns
local grozamodel = game.ReplicatedStorage:WaitForChild("Weapons"):WaitForChild("Groza")
local settings = require(grozamodel.GunComponents.Settings)

--animations
local viewmodel = game.ReplicatedStorage:WaitForChild("Viewmodel")
local animations = game.ReplicatedStorage:WaitForChild("Animations")
local groza = animations:WaitForChild("Groza")

--modules
local module = require(game.ReplicatedStorage.Modules.MainModule)
local spring = require(game.ReplicatedStorage.Modules.SpringModule)
local event = game.ReplicatedStorage:WaitForChild("Event")

viewmodel.Parent = game.Workspace.Camera
module.weldgun(grozamodel)

local recoil = spring.new()
local bobble = spring.new()
local sway = spring.new()

game:GetService("RunService").RenderStepped:Connect(function(dt)
	module.update(viewmodel, dt, recoil, bobble, sway, grozamodel)
end)

module.equip(viewmodel, grozamodel, groza, settings)

local md
local canfire = true

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		md = true
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		module.aim(true, viewmodel, grozamodel)
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		md = false
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		module.aim(false, viewmodel, grozamodel)
	end
end)

local function reloadsound()
	local reloadsound = grozamodel.GunComponents.Sounds.Reload:Clone()
	reloadsound.Parent = game.Workspace
	reloadsound:Destroy()
end

game:GetService("ContextActionService"):BindAction("Reload", function(name, state, input)
	if state == Enum.UserInputState.Begin then
		module.aim(false, viewmodel, grozamodel)
		module.reload(settings, script.Reloading)
		md = false
	end
end, false, Enum.KeyCode.R)

game:GetService("RunService").Heartbeat:Connect(function(dt)
	if md then
		if canfire and script.Reloading.Value == false then
			canfire = false
			
			recoil:shove(Vector3.new(1,math.random(-0.5,0.5),10))
			
			coroutine.wrap(function()
				for i,v in pairs(grozamodel.GunComponents.Barrel:GetChildren()) do
					if v:IsA("ParticleEmitter") then
						v:Emit()
					end
				end
				local firesound = grozamodel.GunComponents.Sounds.Fire:Clone()
				firesound.Parent = game.Workspace
				firesound:Destroy()
			end)()
			
			coroutine.wrap(function()
				wait(0.2)
				recoil:shove(Vector3.new(-0.3, math.random(-0.3,0.3), -10))
			end)()
			
			local castp = RaycastParams.new()
			castp.IgnoreWater = true
			castp.FilterType = Enum.RaycastFilterType.Blacklist
			castp.FilterDescendantsInstances = {viewmodel, game.Players.LocalPlayer.Character}
			
			local mouse = module.getmouse(1000, castp)
			
			module.fire(game.Players.LocalPlayer, mouse, grozamodel.GunComponents.Barrel.Position, settings.vel, settings, game.Players.LocalPlayer.Character)
			event:FireServer({
				["Function"] = "BulletRep",
				["Client"] = game.Players.LocalPlayer,
				["Barrel"] = grozamodel.GunComponents.Barrel.Position,
				["Mouse"] = mouse,
			})	
			
			wait(settings.firerate)
			canfire = true
		elseif script.Reloading.Value == true then
			md = false
		end
	end
end)

event.OnClientEvent:Connect(function(data)
	if data["Function"] == "BulletRep" then
		if data["Client"] ~= game.Players.LocalPlayer then
			module.cast(data["Barrel"], data["Mouse"], 5, nil)
		end
	end
end)

game.ReplicatedStorage.Event2.Event:Connect(function(data)
	if data["Function"] == "Reloadsound" then
		reloadsound()
	elseif data["Function"] == "Unaim" then
		module.aim(false, viewmodel, grozamodel)
	end
end)
1 Like

Well that was a surprise, anyways can you make sure the other sections of code is not interfering with the aim function?

nope i printed toaim every time it gets called and it only prints when i press right click or reload and its the correct value

I meant other parts of the script calling .aim that might can cause some confusion from the scripts because I see module.aim being called from different parts of the code.

Edit: Just the confirm is the value a number value or an integer value?

its a integer that may be the issue, you don’t say which type of value so i assumed integer now its works

2 Likes

Part 3. Pls. I need my gun to switch and that’s a main mechanic to a fps game

2 Likes

If I understand correctly, can’t you just filter the viewmodel from the camera/mouse? That way you can aim down sights and shoot with recoil, without having the bullets fly into your own gun

Can you elaborate more on this sentence?

By Using Mouse.TargetFilter, and adding the player’s viewmodel to the filter, the mouse or whatever should ignore the viewmodel even when your aiming down sights. I haven’t actually read your guide but I think this is what your talking about

.TargetFilter only accepts one Instance, so if you want to blacklist multiple Instances, it would be a hassle to figure out.

I feel like it would be easier than making a mouse module, just use a folder or something