Error in gun system

So im following @EXM_0 tutorial

but ive ran into a roadblock i get this error with the spring module he provided

	local scaledDeltaTime = dt * self.Speed / ITERATIONS

Im 99% sure i did everything right until this error

Here are the scripts:

MainModule
local module = {}

local function GetBobbing(addition)
return math.sin(tick() * addition * 1.3) * 0.5
end

function module.update(viewmodel, dt, recoilspring, bobbleswaying, swayingspring)
viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame

local bobble = Vector3.new(GetBobbing(10), GetBobbing(5),GetBobbing(5))
local mousedelta = game:GetService("UserInputService"):GetMouseDelta()

local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

bobbleswaying:shove(bobble / 10 * (character.HumanoidRootPart.Velocity.Magnitude) / 10)
swayingspring:shove(Vector3.new(-mousedelta.X / 500, mousedelta.Y / 200, 0))

local updatedrecoilspring = recoilspring.update(dt)
local updatedbobblespring = bobbleswaying.update(dt)
local updatedswayingspring = swayingspring.update(dt)

viewmodel.HumanoidRootPart.CFrame = viewmodel.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(updatedbobblespring.Y,updatedb obblespring.X,0))
viewmodel.HumanoidRootPart.CFrame *= CFrame.new(updatedswayingspring.X,updatedswayingspring.Y,0)

viewmodel.HumanoidRootPart.CFrame *= CFrame.Angles(math.rad(updatedrecoilspring.X) * 2,0,0)
game.Workspace.Camera.CFrame *= CFrame.Angles(math.rad(updatedrecoilspring.X),math.rad(updatedrecoilspring.Y),math.rad(updatedrecoilspring.Z))
 end
 --Weld gun or something

 function module.weldgun(gun)
local main = gun.Components.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.Components.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 module.cast(gun, endposition, velocity)
local gunbarrel = gun.Components.Barrel
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(1,1,5)
bullet.Anchored = true
bullet.CanCollide = false
bullet.Color = Color3.new(1, 1, 0)
bullet.Material = Enum.Material.Neon
bullet.Parent = game.Workspace

bullet.CFrame = CFrame.new(gunbarrel.Position, endposition)
local loop
loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
	bullet.CFrame *= CFrame.new(0,0,-velocity * (dt * 60))
	
	
	if (bullet.Position - gunbarrel.Position).magnitude > 5000 then
		bullet:Destroy()
		loop:Disconnect()
	end
end)

end




return module
LocalHandler
local gunmodel = game.ReplicatedStorage:WaitForChild("MiniGun")
local AnimationsFolder = game.ReplicatedStorage:WaitForChild("MiniGunAnimations")
local viewportmodel = game.ReplicatedStorage:WaitForChild("Viewmodel")
local ts = game:GetService("TweenService")
local firing = viewportmodel.AnimationController:LoadAnimation(AnimationsFolder.Firing)
local springmodule = require(game.ReplicatedStorage.SpringModule)
local recoilspring = springmodule.new()
local bobbleswaying = springmodule.new()
local swayspring = springmodule.new()


-- mainmodule idk

 local mainmodule = require(game.ReplicatedStorage.GunSystemMainModule)

viewportmodel.Parent = game.Workspace.Camera

--position viewport model

game:GetService("RunService").RenderStepped:Connect(function(dt)
mainmodule.update(viewportmodel,dt, recoilspring, bobbleswaying, swayspring)
end)

--calls the weldgun thing
mainmodule.weldgun(gunmodel)
--equip thing
mainmodule.equip(viewportmodel,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
		recoilspring:shove(Vector3.new(2,math.random(-2,2),10))
		
		coroutine.wrap(function()
			for i, v in pairs(gunmodel.Components.Barrel:GetChildren()) do
				if v:IsA("ParticleEmitter") then
					v:Emit()
				end
			end
			
			local firesound = gunmodel.Components.Sounds.MiniGunFiring:Clone()

			firesound.Parent = game.Workspace
			firesound.Parent = nil
			firesound:Destroy()
		end)()


		coroutine.wrap(function()
			wait(0.2)
			recoilspring:shove(Vector3.new(-2.8,math.random(-1,1),-10))
		end)()
		recoilspring:shove(Vector3.new(1,0,0))
		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
	firing:Play()
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
	IsPlayerHoldingMouse = false
	firing:Stop()
end
end)

What’s the error? Does it appear in console?

1 Like

This is the error.

This text will be blurred

That looks like a line of code to me, I’m referring to an error which appears in console when attempting to test the script’s execution.

1 Like

Oh opps well the person that made the tutorial replyed about it and helped me fix the error thanks for your help anyways though!

No problem, always the best idea to ask the source for assistance first as they are typically most familiar with their own creations.

2 Likes