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

[HELP] Why does this not work at all? Line 179 "Map is not a valid member of workspace"

Asked by 4 years ago
Edited 4 years ago

I keep getting "Map is not a valid member of workspace line 179"

It works in studio but not in game. Basically I have a "mirror" that puts an object behind the player.

local RunService        = game:GetService('RunService')
local UserInputService  = game:GetService("UserInputService")
local instance,newRay   = Instance.new,Ray.new
local v2,v3,cf,udim2    = Vector2.new,Vector3.new,CFrame.new,UDim2.new
local insert,random,abs = table.insert,math.random,math.abs
local Player            = game.Players.LocalPlayer
local Character         = Player.Character or Player.CharacterAdded:Wait()
local ViewPort          = script.Parent.ViewportFrame
local ReflectionCam     = workspace.ReflectionCam
local ScreenPart        = workspace.Screen
local Camera        = instance("Camera")
    Camera.CFrame           = ReflectionCam.CFrame
    ViewPort.CurrentCamera  = Camera
ReflectionCam:GetPropertyChangedSignal("CFrame"):Connect(function()
    Camera.CFrame           = ReflectionCam.CFrame
end)



local d = math.deg
local function inFOV (p0, p1)
    local x1, y1, z1 = p0:ToOrientation()
    local cf = cf(p0.p, p1.p)
    local x2, y2, z2 = cf:ToOrientation()
    return v3(d(x1-x2), d(y1-y2), d(z1-z2))
end

local Humanoids = {}
local Parts     = {}

local function RenderVersion(obj)
    local Descendants = obj:GetDescendants() 
    for i=1, #Descendants do
        local c = Descendants[i]
        if (c:IsA("Script") or c:IsA("Sound") or c:IsA("ManualWeld") or c:IsA("BasePart"))then
            c:Destroy()
        end
        if c.Name == "ASCEND" then
            c.Transparency = 0
        end
    end
    return obj
end

local function RenderHumanoid(Model, Parent, MainModel)
    local ModelParts = Model:GetChildren()
    for i=1, #ModelParts do
        local Part      = ModelParts[i]
        if not Part:IsA("Script") then
            local a         = Part.Archivable
                Part.Archivable = true
            local RenderClone   = Part:Clone()
                Part.Archivable = a

            if Part:IsA("MeshPart") or Part:IsA("Part") then
                PartUpdater = RunService.Heartbeat:Connect(function()
                    if Part then
                        RenderClone.CFrame = Part.CFrame
                    else
                        RenderClone:Destroy()
                        PartUpdater:Disconnect()
                    end
                end)
            elseif Part:IsA("Accoutrement") then
                PartUpdater = RunService.Heartbeat:Connect(function()
                    if Part then
                        RenderClone.Handle.CFrame = Part.Handle.CFrame
                    else
                        RenderClone:Destroy()
                        PartUpdater:Disconnect()
                    end
                end)
            elseif Part:IsA("Script") then
                RenderClone:Destroy()
            end
            RenderClone.Parent = Parent
        end
    end
end

local function RenderObj(Obj,Parent,Map)
    local ObjParts = Obj:GetChildren()
    for i=1, #ObjParts do
        local Part      = ObjParts[i]
        if Map then
            if Part:IsA("BasePart") or Part:IsA("Model") or Part:IsA("Folder") then
                local a         = Part.Archivable
                    Part.Archivable = true
                local RenderClone   = RenderVersion(Part:Clone())
                    Part.Archivable = a
                RenderObj(Part,RenderClone,Map)
                RenderClone.Parent = Parent
            end
        else
            if Part:IsDescendantOf(workspace) and Part~=workspace then
                if not Parts[Part] and not Humanoids[Part] then
                    if Part:IsA("Model") or Part:IsA("Folder") then
                        if Part:FindFirstChildWhichIsA("Humanoid",true) then
                            Humanoids[Part] = true

                            local ModelClone = instance("Model")
                                ModelClone.Name     = Part.Name

                            RenderHumanoid(Part, ModelClone,ModelClone)
                                ModelClone.Parent   = Parent
                        else
                            local ModelClone = instance("Model")
                                ModelClone.Name     = Part.Name

                            Part.ChildAdded:Connect(function(Child)
                                wait() 
                                RenderObj(Part,ModelClone,Map)
                            end)

                            RenderObj(Part, ModelClone, false)
                                ModelClone.Parent   = Parent
                        end
                    elseif Part:IsA("BasePart") then 
                        if Part~=workspace.Terrain then
                            Parts[Part] = true
                            local a         = Part.Archivable
                                Part.Archivable = true
                            local RenderClone   = RenderVersion(Part:Clone())
                                Part.Archivable = a

                            Part.ChildAdded:Connect(function(Child)
                                wait()
                                RenderObj(Part,RenderClone,Map)
                            end)

                            local LastCF, LastTP, LastColor, LastSize, LastMat = Part.CFrame,Part.Transparency,Part.Color,Part.Size,Part.Material

                            spawn(function()    
                                while wait() do
                                    if Part then
                                        local v = inFOV(Camera.CFrame,Part.CFrame)
                                        if (abs(v.Y+v.X)*2)<(Camera.FieldOfView+40) then 
                                            if LastCF~=Part.CFrame then
                                                LastCF                      = Part.CFrame 
                                                RenderClone.CFrame          = Part.CFrame
                                            end
                                            if LastTP~=Part.Transparency then
                                                LastTP                      = Part.Transparency
                                                RenderClone.Transparency    = Part.Transparency
                                            end
                                            if LastColor~=Part.Color then
                                                LastColor                   = Part.Color
                                                RenderClone.Color           = Part.Color
                                            end
                                            if LastSize~=Part.Size then
                                                LastSize                    = Part.Size
                                                RenderClone.Size            = Part.Size
                                            end
                                            if LastMat~=Part.Material then
                                                LastMat                     = Part.Material
                                                RenderClone.Material        = Part.Material
                                            end
                                        end
                                    else
                                        RenderClone:Destroy()
                                        Parts[Part] = false
                                        break
                                    end
                                end
                            end)
                            RenderObj(Part,RenderClone,Map)
                            RenderClone.Parent = Parent
                        end
                    end
                end
            end
        end
    end
end


wait(1)


RenderObj(workspace,ViewPort)
workspace.ChildAdded:Connect(function(Child)
    wait()
    RenderObj(workspace,ViewPort)
end)


Character.HumanoidRootPart.CFrame = cf(ScreenPart.Position+v3(5,0,0))












0
woah dude, there's a code block for a reason. jorcorrs 76 — 4y
0
Maybe use :FindFirstChild() or :WaitForChild() ChristianTRPOC 64 — 4y

Answer this question