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

What's wrong in this heat vision goggles script?

Asked by 2 years ago

Here's scrpt:

local guiMain = Instance.new("GuiMain")
guiMain.Name = "ThermalGuiMain"
local mode = 0
local thermal = false


function lastParent(obj)
    local object = obj
    local parent = object.Parent
    while true do
        if parent == workspace or parent == game.Lighting or parent == nil then
            return object
        else
            object = parent
            parent = object.Parent
        end
    end
end


function selectAllPartsOfHuman(obj)
    if obj.className == "Part" or obj.className == "Seat" or obj.className == "TrussPart" then
        local selection = Instance.new("SelectionBox")
        selection.Adornee = obj
        selection.Color = BrickColor.new("Really blue")
        selection.Name = "Selection "..obj.Name
        selection.Parent = guiMain
        if obj.Parent:findFirstChild("Humanoid") ~= nil then
            selection.Color = BrickColor.new("Really red")
        end
        obj.AncestryChanged:connect(
        function()
            if obj.Parent == nil or lastParent(obj).Parent ~= workspace then
                selection:remove()
            end
        end)
    else
        for i,child in pairs(obj:getChildren()) do
            selectAllPartsOfHuman(child)
        end
    end
end

function onKeyDown(key)
    if key == "t" then
        if mode == 0 then
            if thermal == false then
                thermal = true
                selectAllPartsOfHuman(game.Workspace)
            elseif thermal == true then
                local child = guiMain:getChildren()
                for i = 1,#child do
                    child[i].Visible = true
                end
            end
            mode = 1
        elseif mode == 1 then
            local child = guiMain:getChildren()
            for i = 1,#child do
                child[i].Visible = false
            end
            mode = 0
        end
    end
end

function onEquipped(mouse)
    local player = game.Players.LocalPlayer
    if player.PlayerGui:findFirstChild("ThermalGuiMain") == nil then
        guiMain.Parent = player.PlayerGui
    elseif player.PlayerGui:findFirstChild("ThermalGuiMain") ~= nil then
        local child = guiMain:getChildren()
        for i = 1,#child do
            child[i].Visible = true
        end
    end
    mouse.KeyDown:connect(onKeyDown)
end

function unEquipped(mouse)
    local child = guiMain:getChildren()
    for i = 1,#child do
        child[i].Visible = false
    end
end

function updateChildren(new)
if mode == 1 then
selectAllPartsOfHuman(new)
end
end



game.Workspace.ChildAdded:connect(updateChildren)


script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(unEquipped)

I don't know if the script is still working, because I was programming it a long time ago.

1
What's the issue? I can't understand anything if you don't tell the issue. enes223 327 — 2y

Answer this question