i was making a fps gun system and when i was gonna make the walking anim i didnt animate it. I used scripting to move it around like a walking anim and it broke by that. Idk if anyone can fix it or even help but here is the code anyway. SCroll tgrough until you find a text that says "THIS IS THE ONLY THING THAT HAS AN ERROR" line 91
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local aimCF = CFrame.new()
local isAiming = false
local currentSwayAMT = -.4
local swayAMT = -.4
local aimSwayAMT = .3
local swayCF = CFrame.new()
local lastCameraCF = CFrame.new()
local framework = {
inventory = {
"MP5SD";
"DEAGLE";
"SHOTGUN";
};
module = nil;
viewmodel = nil;
currentSlot = 1;
}
function loadSlot(Item)
local viewmodelFolder = game.ReplicatedStorage.Viewmodels
local moduleFolder = game.ReplicatedStorage.Modules
for i,v in pairs(camera:GetChildren()) do
if v:IsA("Model") then
v:Destroy()
end
end
if moduleFolder:FindFirstChild(Item) then
framework.module = require(moduleFolder:FindFirstChild(Item))
if viewmodelFolder:FindFirstChild(Item) then
framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone()
framework.viewmodel.Parent = camera
end
end
end
RunService.RenderStepped:Connect(function()
end)
local rot = camera.CFrame:ToObjectSpace(lastCameraCF)
local X,Y,Z = rot:ToOrientation()
swayCF = swayCF:Lerp(CFrame.Angles(math.sin(X) * currentSwayAMT, math.sin(Y) * currentSwayAMT, 0), .1)
lastCameraCF = camera.CFrame
local humanoid = character:WaitForChild("Humanoid")
if humanoid then
local bobOffset = CFrame.new(math.abs(math.cos(tick() * 10)) * .2, -humanoid.CameraOffset.Y/3, -humanoid.CameraOffset.Z/3)
if humanoid.MoveDirection.Magnitude > 0 then
if humanoid.WalkSpeed == 16 then
bobOffset = CFrame.new(math.abs(math.cos(tick() * 10)) * .2, -humanoid.CameraOffset.Y/3, -humanoid.CameraOffset.Z/3)
elseif humanoid.WalkSpeed == 30 then
end
else
bobOffset = CFrame.new(0 * .2, -humanoid.CameraOffset.Y/3, 0)
end
end)
for i, v in pairs(camera:GetChildren()) do
if v:IsA("Model") then
v:SetPrimaryPartCFrame(camera.CFrame * swayCF * aimCF * bobOffset)
end
end
end
if isAiming and framework.viewmodel ~= nil and framework.module.canAim then
local offset = framework.viewmodel.AimPart.CFrame:ToObjectSpace(framework.viewmodel.PrimaryPart.CFrame)
aimCF = aimCF:Lerp(offset, framework.module.aimSmooth)
currentSwayAMT = aimSwayAMT
else
local offset = CFrame.new()
aimCF = aimCF:Lerp(offset, .1)
currentSwayAMT = swayAMT
end
end) -- THIS IS THE ONLY THING THAT HAS AN ERROR
loadSlot(framework.inventory[1])
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.One then
if framework.currentSlot ~= 1 then
loadSlot(framework.inventory[1])
framework.currentSlot = 1
end
end
if input.KeyCode == Enum.KeyCode.Two then
if framework.currentSlot ~= 2 then
loadSlot(framework.inventory[2])
framework.currentSlot = 2
end
end
if input.KeyCode == Enum.KeyCode.Three then
if framework.currentSlot ~= 3 then
loadSlot(framework.inventory[3])
framework.currentSlot = 3
end
end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = true
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = false
end
end)
