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

I've been trying to make an invisibility cloak but it won't work. Is it about scripting or spelling?

Asked by 4 years ago

This is the script:

tool = script.Parent
player = game.Players.LocalPlayer

toggle = false
folder = nil

function CreateFolder()
    if player:FindFirstChildClass("Folder") == nil then
        folder = Instance.new("Folder", player)
        folder.Name = "Accessories"
    end
end

local function MoveAccessories(str)
    if str == "Player" then
        accessories = folder:GetChildren()
    elseif str == "Folder" then
        accessories = player.Character:GetChildren()
    end
end

CreateFolder()

function Toggle()
    if toggle == false then
        toggle = true
    else
        toggle =false
    end
end

function SetVisibility()
    local function SetPartVisible(trans)
        local human = player.Character:GetChildren()

        for i, part in ipairs(human) do
            if part:IsA("Part")and part.Name == "HumanoidRoot" then
                if str == "Player" then
                    item.Parent = player.Character
                elseif str == "Folder" then
                    item.Parent = folder
                end
            end
        end
    end

    local function MoveFace(str)
        if str == "Player" then
            folder.face.Parent = player.Character.Head.
        elseif str == "Folder" then
            player.Character.head.face.Parent = folder
        end

    if toggle == true then
        SetPartVisible(1)
        MoveAccessories("Folder")
        MoveFace("Folder")
    else
        SetPartVisible(0)
        MoveAccessories ("Player")
        MoveFace("Player")
    end
end

tool.Activated:connect(function()
    toggle()
    SetVisibility()
end)
0
you can use the roblox invisible cape that's already made MinuhaYT 19 — 4y
0
Any errors? SimplifiedCode 227 — 4y
0
No errors, but when I click it it wont go invisible. It doesn't give any errors in the output. But the tool doesn't work. wir_superise 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I went through your code, I there is a lot messed up, you forget ends, you don't capitalize somethings and there are just some functions that seem unnecessary. I recommend re-scripting it entirely. Heres a checklist:

  • Function for Toggle
  • Function for Invisibility
  • Event for when the tool is used

(you don't need to store the accessories, you can make them invisible also by finding their handle.)

Here's and example I just cooked up

tool = script.Parent
player = game.Players.LocalPlayer
toggle = 0
function Toggle()
    if toggle == 1 then
        toggle = 0
    elseif toggle == 0 then
        toggle = 1
    end
end

function invisibility()
    for _, item in pairs(player.Character:GetChildren()) do
        if item:IsA("Part") and item.Name ~= "HumanoidRootPart" then
            if item.Name == "Head" then
                item.face.Transparency = toggle
                item.Transparency = toggle
            else
                item.Transparency = toggle
            end
        elseif item:IsA("MeshPart") then
            item.Transparency = toggle
        elseif item:IsA("Accessory") then
            item.Handle.Transparency = toggle
        end
    end
end

tool.Activated:Connect(function()
    Toggle()
    invisibility()
end)
Ad

Answer this question