How to make viewmodel sway without using springs? - Roblox Studio

Hello, I want to make a sway effect for my viewmodel in roblox studio, but when trying to use springs, it just doesn’t work. Is there any other way to do this than using springs? Here’s my script (Note: I use tools for the guns)

local UIS = game:GetService("UserInputService")
local springModule = require(game.ReplicatedStorage.Modules.Spring)
local camera = workspace.CurrentCamera

-----------------------------------------------------------------------------------------------------------------

local equipped = false
local Viewmodel
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Idle
local Aim
-----------------------------------------------------------------------------------------------------------------
local aiming = false
local running = false
-----------------------------------------------------------------------------------------------------------------
local aimCF = CFrame.new()
--local ProjectileModule = require(game.ReplicatedStorage.Viewmodels.Glock17.ProjectileModule)
--local VFXModule = require(script["VFX Handler"])
-----------------------------------------------------------------------------------------------------------------
local function Equip()
	Viewmodel = game.ReplicatedStorage.Viewmodels.Glock17:Clone()
	-----------------------------------------------------------------------------------------------------------------
	
	-----------------------------------------------------------------------------------------------------------------
	Viewmodel.Parent = game.Workspace.CurrentCamera
	Idle = Viewmodel.AnimationController:LoadAnimation(script.ViewModelAnimations.Idle)
	
	Idle:Play()
	
	
	-----------------------------------------------------------------------------------------------------------------
	if not equipped then
		equipped = true
	end

end


-----------------------------------------------------------------------------------------------------------------
mouse.Button2Down:Connect(function()
	aiming = true
end)
-----------------------------------------------------------------------------------------------------------------
mouse.Button2Up:Connect(function()
	aiming = false
end)




-----------------------------------------------------------------------------------------------------------------
RunService.RenderStepped:Connect(function(DT)
local Aim = Viewmodel:FindFirstChild("AnimationController"):LoadAnimation(script.ViewModelAnimations.Aim)
	if aiming then
        if Viewmodel:FindFirstChild("HumanoidRootPart") then
		aimCF = aimCF:Lerp(Viewmodel.FakeCamera.Aim.WorldCFrame:ToObjectSpace(Viewmodel.PrimaryPart.CFrame), .5)
		end
		--Idle:Stop()
	else
		if Viewmodel:FindFirstChild("FakeCamera") then
		aimCF = aimCF:Lerp(CFrame.new() ,.5)
		--Idle:Play()
		end
		
	end

	-----  ------------------------------------------------------------------------------------------------------------
	if Viewmodel then
	Viewmodel:PivotTo(
  
		camera.CFrame  * (aimCF  * CFrame.new(0,0,0))
---* CFrame.new(0, -0.5, 0.45)) CFrame.new(0,0.5,0)
	)
	end
end)
-----------------------------------------------------------------------------------------------------------------
local function UnEquip()
	if Viewmodel then
		Viewmodel:Destroy()
		equipped = false
	end
end


-----------------------------------------------------------------------------------------------------------------
local function Shoot()
--WIP
end
-----------------------------------------------------------------------------------------------------------------
script.Parent.Equipped:Connect(Equip)
script.Parent.Unequipped:Connect(UnEquip)```

Sorry for the weird format :frowning: And also sorry if it’s hard to read :frowning:

if you want to format it correctly use backticks ` basically put three of them on the line before your code start’s and three on the line after the code end’s, like so:

– ```

– code here

–```
without the hyphons, of course.

and here’s a fully formatted version of your code:

local RunService = game:GetService(“RunService”)
local UIS = game:GetService(“UserInputService”)
local springModule = require(game.ReplicatedStorage.Modules.Spring)
local camera = workspace.CurrentCamera

local equipped = false
local Viewmodel
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Idle
local Aim
local aiming = false
local running = false
local aimCF = CFrame.new()
–local ProjectileModule = require(game.ReplicatedStorage.Viewmodels.Glock17.ProjectileModule)
–local VFXModule = require(script[“VFX Handler”])
local function Equip()
Viewmodel = game.ReplicatedStorage.Viewmodels.Glock17:Clone()
-----------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------
Viewmodel.Parent = game.Workspace.CurrentCamera
Idle = Viewmodel.AnimationController:LoadAnimation(script.ViewModelAnimations.Idle)

Idle:Play()


-----------------------------------------------------------------------------------------------------------------
if not equipped then
	equipped = true
end
end

mouse.Button2Down:Connect(function()
aiming = true
end)
mouse.Button2Up:Connect(function()
aiming = false
end)

RunService.RenderStepped:Connect(function(DT)
local Aim = Viewmodel:FindFirstChild(“AnimationController”):LoadAnimation(script.ViewModelAnimations.Aim)
if aiming then
if Viewmodel:FindFirstChild(“HumanoidRootPart”) then
aimCF = aimCF:Lerp(Viewmodel.FakeCamera.Aim.WorldCFrame:ToObjectSpace(Viewmodel.PrimaryPart.CFrame), .5)
end
–Idle:Stop()
else
if Viewmodel:FindFirstChild(“FakeCamera”) then
aimCF = aimCF:Lerp(CFrame.new() ,.5)
–Idle:Play()
end

end

-----  ------------------------------------------------------------------------------------------------------------
if Viewmodel then
Viewmodel:PivotTo(

	camera.CFrame  * (aimCF  * CFrame.new(0,0,0))
—* CFrame.new(0, -0.5, 0.45)) CFrame.new(0,0.5,0)
)
end
end)
local function UnEquip()
if Viewmodel then
Viewmodel:Destroy()
equipped = false
end
end

Thanks, It’s my first post so i don’t know much about how to format stuff lol