Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

FE Script not working when trying to fire, attempted to nil with 'CFrame' (?)

Asked by 1 year ago

Ello Developers!

I have no fu[Censored]king reason why the hell the script decided to not follow It, I am making a FE Game and the Issue Is where If you where to press right mouse key to aim It, It does nothing and just gives me that stupid error, Its a local script In StarterPlayerFolder btw, I am following this tutorial: https://www.youtube.com/watch?v=I2b4BcP6pUA

(Also, Main Is a part In Line 56)

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Camera = game.Workspace.CurrentCamera
local aimCFrame = CFrame.new()
local Frameworks = {
    Inventory = {
        "XLS Mark"
    };
    module = nil;
    viewmodel = nil;
    CurrentWeapon = 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
        Frameworks.module = require(moduleFolder:FindFirstChild(Item))


        if viewModelFolder:FindFirstChild(Item) then
            Frameworks.viewmodel = viewModelFolder:FindFirstChild(Item):Clone()
            Frameworks.viewmodel.Parent = Camera
        end
    end
end

RunService.RenderStepped:Connect(function()
    for i,v in pairs(Camera:GetChildren()) do
        if v:IsA("Model") then
            v:PivotTo(Camera.CFrame * aimCFrame)
        end
    end
end)

loadSlot(Frameworks.Inventory[1])

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.One then
        if Frameworks.CurrentWeapon ~= 1 then
            loadSlot(Frameworks.Inventory[1])
            Frameworks.CurrentWeapon = 1
        end
    end

    if input.UserInputType == Enum.UserInputType.MouseButton2 then
        local offset = Frameworks.viewmodel.Main.CFrame:ToObjectSpace(Frameworks.viewmodel.PrimaryPart.CFrame)
        aimCFrame = aimCFrame:Lerp(offset, .1)
    end
end)

UIS.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton2 then
        print("User stop firing")
    end
end)

Answer this question