Designing an FPS Framework: Beginner's guide

Yeah I don’t know why it spawns at 0,0,0, but it just does. Also, I used 60 velocity, like you did in your gun, but it moves way faster than your gun. Also reloading is already kind of simple, so I could probably do it myself.

1 Like

That’s because I forgot to do dt * 60. I updated the script but I didn’t update the video.

Here is what I said in Part 2:

image

3 Likes

I printed the position of the bullet, spawns at 0,0,0. I did some extra testing, but nothing else important came up.

2 Likes

Do this also, this way we know if the bullet is spawning to actually positioning to the right position.

And also this.

2 Likes

I did print the barrels position, it’s fine. I modified the module to set the bullets position to the barrel, it works, but after 5-7 seconds, the bullet disappears. The bullet’s position isn’t 0,0,0 anymore, even when the bullet doesn’t appear.

2 Likes

Could you make a video showing this or instead make the game public so I can see the problem myself

2 Likes

It’s a local file, I will publish a game in a second…

game link ^

This is the output of me shooting:


There is no bullets.

3 Likes

Try and set the velocity to like 5, 60 may be too fast and also I noticed that the Y axis is going around -600…?

3 Likes

I think they’re spawning underground. When I go into first person, the bullets go away.
Also, if possible, could you provide an rbxm file of the module script for part 1?

2 Likes

When ingame could you check if the gun is welded properly, and also may I see the LocalHandler?

Unfortunately, No. I already provided the source code below. I don’t want people to gain nothing out of my tutorial (also another reason I don’t use code blocks). Sorry!

4 Likes

1:
Screenshot 2021-05-05 102903

Screenshot 2021-05-05 102922

2:

local GunModel = game.ReplicatedStorage:WaitForChild("SR01A1")
local AnimationsFolder = game.ReplicatedStorage:WaitForChild("SR01A1_ANIMS")
local ViewModel = game.ReplicatedStorage:WaitForChild("ViewModel")
local Mouse = game.Players.LocalPlayer:GetMouse()

local MainModule = require(game.ReplicatedStorage:WaitForChild("MainModule"))

ViewModel.Parent = workspace.Camera
MainModule.weldgun(GunModel)

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

MainModule.equip(ViewModel,GunModel,AnimationsFolder.SR01A1_ANIM)

local IsPlayerHoldingMouse
local CanFire = true
local FireDelay = 0.1

game:GetService("RunService").Heartbeat:Connect(function(dt)
	if IsPlayerHoldingMouse then
		if CanFire then
			CanFire = false

			MainModule.cast(GunModel, Mouse.Hit.Position, 5)

			wait(FireDelay)
			print(ViewModel.SR01A1.GunComponets.Barrel.Position)
			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").InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		IsPlayerHoldingMouse = false
	end
end)

3: That’s alright, it’s just hard to see the module in a small image.

2 Likes

Are you modifying the barrel’s position in another script? because the barrel’s position is sometimes going into the negatives…?

2 Likes

module:



local MainModule = {}

function MainModule.Update(viewmodel, dt)
	viewmodel.HumanoidRootPart.CFrame = workspace.Camera.CFrame
end

function MainModule.weldgun(gun)
	local Main = gun.GunComponets.Handle

	for i,v in ipairs(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 MainModule.equip(viewmodel, gun, hold)
	local GunHandle = gun.GunComponets.Handle
	local HRP_Motor6D = viewmodel:WaitForChild("HumanoidRootPart").Handle

	gun.Parent = viewmodel
	HRP_Motor6D.Part1 = GunHandle

	local Hold = viewmodel.AnimationController:LoadAnimation(hold)
	Hold:Play()
end

function MainModule.cast(gun,endposition,velocity)
	local GunBarrel = gun.GunComponets:WaitForChild("Barrel")

	local Bullet = Instance.new("Part")
	Bullet.Size = Vector3.new(1,1,5)
	Bullet.Anchored = true
	Bullet.CanCollide = false
	Bullet.Color = Color3.new(255,255,255)
	Bullet.Material = Enum.Material.Neon
	Bullet.Parent = workspace

	Bullet.CFrame = CFrame.new(Bullet.Position, endposition)
	Bullet.Position = GunBarrel.Position
	print(Bullet.Position)
	
	local Loop

	Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
		Bullet.CFrame *= CFrame.new(0, 0, -velocity * (dt * 5))
		if (Bullet.Position - GunBarrel.Position).magnitude > 1000 then
			Bullet:Destroy()
			Loop:Disconnect()
		end
	end)
end


return MainModule

Without Bullet.Position = GunBarrel.Position the bullet spawns at 0,0,0

2 Likes

Hm that’s weird could you try replacing your gun with my gun that I used in the tutorial:

groza.rbxm (8.7 KB)

You could also remove this Bullet.Position = GunBarrel.Position when testing with the gun I gave you

2 Likes

I misspelled “GunComponents” to “GunComponets” on some lines of code, so that might cause this issue. Also the same thing happens, the bullet spawns at 0,0,0

3 Likes

image

Uh, it should be CFrame.new(GunBarrel.Position, endposition). I honestly don’t know why I haven’t notice this earlier.

2 Likes

I tried that, never worked when I did that. I will try again, that was basically the entire reason I created a topic to fix this.

2 Likes

Well it should be that, doing Bullet.Position is just setting to its own position.

2 Likes

It shoots, unlike before when I tried that, but it spawns in a random position, not the barrel. It’s probably not random, but it’s confusing.

2 Likes

A video showing the problem would be much appreciated, also

Have you removed this line?

2 Likes