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

Vector3 Expected; got nil?

Asked by 5 years ago

Working on a GUI when I stumbled on an error with vector3's. An error on line 8

local function GenerateSelectionModel()
    if SelectionModel then
        SelectionModel:Destroy()
    end
    local Prefab = PrefabTable[SelectionNumber]
    if Prefab then
        SelectionModel = Prefab:Clone()
        SelectionModel:SetPrimaryPartCFrame(CFrame.new(Mouse.Hit.p) * CFrame.Angles(0, math.rad(CurrentRotation), 0) * CFrame.new(SelectionModel:FindFirstChild("Compensation")) or {Value = Vector3.new() * CFrame.new(0, SelectionModel.PrimaryPart.Size.Y / 2, 0)})
        local Cache = SelectionModel:GetDescendants()
        Mouse.TargetFilter = SelectionModel
        for i = 1, #Cache do
            if Cache[i]:IsA("BasePart") then
                Cache[i].Material = Enum.Material.Glass
                if Cache[i]:IsA("UnionOperation") then
                    Cache[i].UsePartColor = true
                end
                if Cache[i]:IsA("Seat") then
                    Cache[i].Disabled = true
                end
                if Cache[i].Transparency ~= 1 then
                    Cache[i].Transparency = 0.5
                end
                Cache[i].CanCollide = false
            end
        end
        if Equipped then
            SelectionModel.Parent = PrefabsFolder
        end
    end
end

This is a local script inside StarterCharacterScripts; if you need more information do ask. Thanks

0
can you explain the logic behind line 8? User#5423 17 — 5y
1
There is a lot going on and you probably should use a variable to help with the readability of the code User#5423 17 — 5y
0
I am using variables. That's mostly the reason on why im confused why this isnt working- if you're wondering the output this is it https://gyazo.com/576cd18835a6fa68b41505bd9be416be IrishStukov 20 — 5y
1
because your code is extremely messy User#19524 175 — 5y
View all comments (3 more)
0
Sorry for that IrishStukov 20 — 5y
0
Is there anything im doing wrong though? IrishStukov 20 — 5y
0
Like they said above, you should split that giant line into several variables so it would be like SetPrimaryPartCFrame(CFrame1 or CFrame2) that way you have at least a general idea of what is specifically erroring, it's very difficult with the amount of paranthesis currently to decipher the logic in it Vulkarin 581 — 5y

Answer this question