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

My Holo Script Isn't Working... Help?

Asked by 9 years ago

Right, so when I run the following script:

Maps = require(script.Maps)
Functions = require(script.Functions)

wait(2)
Functions.StartSim(Maps.Cabin)
wait(10)
Functions.EndSim()

It accesses 2 module scripts. I can confirm that the one containing the maps is 100% working, what I'm having trouble with is the Functions one. This is the script from there:

local Selectors = {
    game.Workspace["Holo System"].Generator.SelectionBox;
    game.Workspace["Holo System"].Generator.Connection
}

local Functions = {}

Functions.StartSim = function(Map)
    local Simulation = Instance.new("Model", game.Workspace)
    Simulation.Name = "Simulation"
    for _,v in pairs(Selectors) do
        v.Visible = true
    end

    for _,v in pairs(Map:GetChildren()) do
        v.Parent = Simulation
        for _,p in pairs(Selectors) do
            if p:IsA("SelectionBox") then
                p.Adornee = v
            elseif p:IsA("SelectionPartLasso") then
                p.Part = v
            end
        end
        wait()
        for _,c in pairs(Selectors) do
            if c:IsA("SelectionBox") then
                c.Adornee = nil
            elseif c:IsA("SelectionPartLasso") then
                c.Part = nil
            end
        end
    end
    for _,v in pairs(Selectors) do
        v.Visible = false
    end
end

Functions.EndSim = function()
    if not game.Workspace:FindFirstChild("Simulation") then return end
    local Simulation = game.Workspace:FindFirstChild("Simulation")
    for _,v in pairs(Selectors) do
        v.Visible = true
    end

    for _,v in pairs(Simulation:GetChildren()) do
        for _,c in pairs(Selectors) do
            if c:IsA("SelectionBox") then
                c.Adornee = v
            elseif c:IsA("SelectionPartLasso") then
                c.Part = v
            end
        end
        wait()
        for _,c in pairs(Selectors) do
            if c:IsA("SelectionBox") then
                c.Adornee = nil
            elseif c:IsA("SelectionPartLasso") then
                c.Part = nil
            end
            v:Destroy()
        end
    end
    for _,v in pairs(Selectors) do
        v.Visible = false
    end
end

return Functions

The error thrown in the output box reads:

19:43:05.250 - std::bad_cast
19:43:05.251 - Script 'Workspace.Holo System.Computer.Aurum's Holo Script.Function', Line 21 - field StartSim
19:43:05.251 - Script 'Workspace.Holo System.Computer.Aurum's Holo Script', Line 5
19:43:05.260 - Stack End

I have no idea why it's throwing at line 21, as all of it seems perfectly fine. The script is supposed to do what a holo training does, make a beam to a part that appears and lay down the map.

Any and all help appreciated.

Thanks in advance, AurumAquila

Answer this question