Invisibility tool

Hi, I am making a cloak tool for my game that makes you invisible.

This is my current code:

local InvisibleEvent = game.ReplicatedStorage.InvisibleEvent
local Player = game.Players.LocalPlayer
local Invisible = nil

script.Parent.Activated:Connect(function()
	local Character = game.Workspace:FindFirstChild(Player.Name)

	for i,v in pairs(Character:GetChildren()) do
		if v.ClassName == "MeshPart" then
			if v.Transparency == 0 then
				Invisible = false
				InvisibleEvent:FireServer(Character, Invisible)
			elseif v.Transparency == 1 then
				Invisible = true
				InvisibleEvent:FireServer(Character, Invisible)
			end
		end
	end
end)

That is a local script inside of the tool.

This next one is in Server Script Service

local InvisibleEvent = game.ReplicatedStorage.InvisibleEvent


InvisibleEvent.OnServerEvent:Connect(function(plr, character, invisible)
	print("I got here")
	if invisible == true then
		for i,v in pairs(character:GetChildren()) do
			if v.ClassName == "MeshPart" then
				if v.Name == "Head" then
					v.Transparency = 0
					v.face.Transparency = 0
				else
					v.Transparency = 0
				end
			end
		end
	elseif invisible == false then
		for i,v in pairs(character:GetChildren()) do
			if v.ClassName == "Part" then
				if v.Name == "Head" then
					v.Transparency = 1
					v.face.Transparency = 1
				else
					v.Transparency = 1
				end
			elseif v.ClassName == "Accessory" then
				v:Destroy()   
			end
		end
	end
end)

It does not work and I get no errors.

Any help is appreciated.

1 Like

Looks like you are over complicating things, I would just put a server script inside the tool with something like this

local tool = script.Parent

local character = nil
local invisible = false

local function toggle(bool)
	invisible = (bool == nil and not invisible) or bool
	local newTransparency = invisible and 1 or 0
	
	for i,descendant in character:GetDescendants() do
		if not (descendant:IsA('BasePart') or descendant:IsA('Decal')) or descendant.Name == 'HumanoidRootPart' then continue end
		descendant.Transparency = newTransparency
	end
end

tool.Unequipped:Connect(function() toggle(false) character = nil end)
tool.Equipped:Connect(function() character = tool.Parent end)
tool.Activated:Connect(toggle)

Also just in case you don’t know, if your tool doesn’t have a handle and you don’t have RequiresHandle disabled, then it wont detect when the tool is activated

4 Likes

@MineplackStudios
Here I hope this help you
local script: (tool must have part named Handle) (script parent = tool) (tool handle must be transparency 0)

local remote = game.ReplicatedStorage.RemoteEvent

script.Parent.Equipped:Connect(function()
	IsToolActive = true
	remote:FireServer(IsToolActive)
end)

script.Parent.Unequipped:Connect(function()
	IsToolActive = false
	remote:FireServer(IsToolActive)
end)

server script:

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(plr, ToolInfo)
	IsToolActive = ToolInfo
	if IsToolActive == true then
		plr.Character.Head.face.Transparency = 1
		for i,v in pairs(plr.Character:GetChildren()) do
			if v.ClassName == "Accessory" then
				for i,v in pairs(v:GetChildren()) do
					if v.ClassName == "Part" then
						v.Transparency = 1				
					end
				end
			end
			if v.ClassName == "Part" then
				v.Transparency = 1
			end
		end
	else
		plr.Character.Head.face.Transparency = 0
		for i,v in pairs(plr.Character:GetChildren()) do
			if v.ClassName == "Accessory" then
				for i,v in pairs(v:GetChildren()) do
					if v.ClassName == "Part" then
						v.Transparency = 0				
					end
				end
			end
			if v.ClassName == "Part" then
				v.Transparency = 0
			end
			plr.Character.HumanoidRootPart.Transparency = 1
		end
	end
end)

put RemoteEvent in ReplicatedStorage
I hope this help you mark this as solution pls :slightly_smiling_face:

In StarterPack
InvisibilityCloak.rbxm (5.4 KB)

Invisibility Script
-- Non-local script ServerScriptService.Invisibility

local tween = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local re = Instance.new("RemoteEvent")
re.Name = "Invisibility" ;re.Parent = rs

local inv = rs.Invisibility
inv.OnServerEvent:Connect(function(player, mode)
	local chr = player.Character
	local inf = TweenInfo.new(1,Enum.EasingStyle.Circular, Enum.EasingDirection.In)
	for _, object in ipairs(chr:GetDescendants()) do
		if object:IsA("BasePart") or object:IsA("Decal") then
			if object.Name ~= "HumanoidRootPart" then
				if mode == true then
					local fade = tween:Create(object, inf, {Transparency = 1})
					fade:Play()
				elseif mode == false then
					local fade = tween:Create(object, inf, {Transparency = 0})
					fade:Play()
				end
			end
		end
	end
end)

Messed around with this a while back. Tried to make it not so totally OP.
This is a tool that has to be activated. That means no other tool can be.
You can move as normal but you will have to remove the cloak to do things.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.