Ad
Log in to vote
0

How do you store a CFrame value in a table?

Asked by 3 months ago
Edited 3 months ago

I'm experimenting with CFrame and tried storing a CFrame value to a table. I had struggles with it. How do you do it?

Here's my code and please answer with details. My code is some kind of detection. I think detection of which if a part went out of a certain area it will turn red, otherwise green.

BrickMode = true -- Just some kind of mode to find it using parts. I need to make invisible points without depending on bricks. Just CFrame points.









model = nil
axis = 1
neg = 0
if BrickMode == true then
    if workspace:FindFirstChild('SurfaceDetectionPoints') then
    model = workspace.SurfaceDetectionPoints
    else
        Instance.new("Model",workspace).Name = 'SurfaceDetectionPoints'
        model = workspace.SurfaceDetectionPoints
    end
    for o = 1,6 do
        newIns = Instance.new("Part",model)
        newIns.Color = Color3.new(0,1,0)
        newIns.Anchored = true
        newIns.Size = Vector3.new(0.2,0.2,0.2)
        newIns.Material = "Neon"
        newIns.CanCollide = false
        newIns.Name = "SURFACEDETECTIONPART"
    end
end
-- Creates an instance for keeping the parts
while true do

    size = script.Parent.Size
    points = {
        script.Parent.Size.Z / 2,
        script.Parent.Size.Z / 2,
        script.Parent.Size.X / 2,
        script.Parent.Size.X / 2,
        script.Parent.Size.Y / 2,
        script.Parent.Size.Y / 2
    }
    -- Above are points for simple surface detection.


    if BrickMode == true then
        newPart = model:GetChildren()
    end
    for i = 1,#points do
        invisPoints = {}
        -- setting
        cAxis = nil
        if axis == 1 then
            if neg == 0 then
                cAxis = Vector3.new(0,0,points[i])
            else
                cAxis = Vector3.new(0,0,-points[i])
            end
        elseif axis == 2 then
            if neg == 0 then
                cAxis = Vector3.new(points[i],0,0)
            else
                cAxis = Vector3.new(-points[i],0,0)
            end
        elseif axis == 3 then
            if neg == 0 then
                cAxis = Vector3.new(0,points[i],0)
            else
                cAxis = Vector3.new(0,-points[i],0)
            end

        end

        -- start

        if BrickMode == true then
            newPart[i].CFrame = CFrame.new(script.Parent.Position)
            *CFrame.fromOrientation(math.rad(script.Parent.Orientation.X),math.rad(script.Parent.Orientation.Y),math.rad(script.Parent.Orientation.Z))
            *CFrame.new(cAxis)
        end
        table.insert(invisPoints,nil,{CFrame.new(script.Parent.Position)
            *CFrame.fromOrientation(math.rad(script.Parent.Orientation.X),math.rad(script.Parent.Orientation.Y),math.rad(script.Parent.Orientation.Z))
            *CFrame.new(cAxis)}) -- Where it went down. <<<<<<<<<<<<<<<<<<<
        -- presetting
        if neg == 1 then
            if axis == 1 then
            axis = 2
            elseif axis == 2 then
                axis = 3
            elseif axis == 3 then
                axis = 1
            end
        end
        if neg == 0 then
            neg = 1
        else
            neg = 0
        end
    end
    calcWidth = {left = workspace.Inside.Position.X + (workspace.Inside.Size.X/2), right = workspace.Inside.Position.X - (workspace.Inside.Size.X/2)}
    calcHeight = {up = workspace.Inside.Position.Y + (workspace.Inside.Size.Y/2), down = workspace.Inside.Position.Y - (workspace.Inside.Size.Y/2)}
    calcLength = {front = workspace.Inside.Position.Z + (workspace.Inside.Size.Z/2), back = workspace.Inside.Position.Z - (workspace.Inside.Size.Z/2)}
    --============BRICK MODE============--
    if BrickMode == true then
        local pass = 0
        local passes = {}
        region = Region3.new(Vector3.new(calcWidth.right,calcHeight.down,calcLength.back), Vector3.new(calcWidth.left,calcHeight.up,calcLength.front))
        detect = workspace:FindPartsInRegion3(region)
        for _,Part in pairs(detect) do
            if Part.Name == 'SURFACEDETECTIONPART' then
                pass = pass + 1
            end
        end
        if pass == 6 then
            for k = 1,#newPart do
                newPart[k].Color = Color3.new(0,1,0)
            end
        else
            for k = 1,#newPart do
                newPart[k].Color = Color3.new(1,0,0)
            end
        end
    else
        local passes = 0
        for j = 1,#invisPoints do
            if invisPoints[j].X < calcWidth.left and invisPoints[j].X > calcWidth.right and invisPoints[j].Y < calcHeight.up and invisPoints[j].Y > calcHeight.down and invisPoints[j].Z < calcLength.front and invisPoints[j].Z > calcLength.back then
                passes = passes + 1
            end
        end
        if passes == 6 then
            script.Parent.Color = Color3.new(0,1,0)
        else
            script.Parent.Color = Color3.new(1,0,0)
        end
    end
    --============BRICK MODE END============--
    wait(0.01) -- for seeing the parts in a limited time.
end

Thanks in advance.

11:53 PM 5/16/2018 Philippine Time

Good night.

Answer this question