Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

3 comments

0

you can use the roblox invisible cape that's already made

0

Any errors?

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.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.