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

My R6 invisibility tool script isn't working and nothing shows in output. Why?

LocalScript in tool:



local tool = script.Parent
local char = tool.Parent.Parent.Character

local function onActivate()	
char.Head.Transparency = 1
char['Right Arm'].Transparency = 1
char['Left Arm'].Transparency = 1
char.Torso.Transparency = 1
char['Right Leg'].Transparency = 1
char['Left Leg'].Transparency = 1
		
local function onUnequip()
	char.Head.Transparency = 0
char['Right Arm'].Transparency = 0
char['Left Arm'].Transparency = 0
char.Torso.Transparency = 0
char['Right Leg'].Transparency = 0
char['Left Leg'].Transparency = 0
end
end

1 answer

✓ Accepted answer

You have to link the functions to the Equipped and Activate events (and also move your ends around):

local tool = script.Parent

local function onActivate() 
	local char = tool.Parent.Parent
	char.Head.Transparency = 1
	char['Right Arm'].Transparency = 1
	char['Left Arm'].Transparency = 1
	char.Torso.Transparency = 1
	char['Right Leg'].Transparency = 1
	char['Left Leg'].Transparency = 1
end
tool.Activated:Connect(onActivate)

local function onUnequip()
	local char = tool.Parent.Parent
	char.Head.Transparency = 0
	char['Right Arm'].Transparency = 0
	char['Left Arm'].Transparency = 0
	char.Torso.Transparency = 0
	char['Right Leg'].Transparency = 0
	char['Left Leg'].Transparency = 0
end
tool.Unequipped:Connect(onUnequip)

But a better way to do it might be to iterate through the children of the character and set the transparency of all the parts to 0/1:

function setTransparency(trans)
	local char = script.Parent.Parent
	for _,v in pairs(char:GetDescendants()) do
		if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
			v.Transparency = trans
		end
	end
end
script.Parent.Equipped:Connect(function()
	setTransparency(1)
end)
script.Parent.Unequipped:Connect(function()
	setTransparency(0)
end)

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