I’m attempting to make a simple tool that turns the player invisible, but not the tool itself. I’m using a basic invisibility tool script I pulled from toolbox, but it makes the tool invisible as well. When I tried to fix this, it made both the player and tool visible again, so I assume I’ve simply put the loop in the wrong location.
Here’s the script, with my modifications labelled:
local p = game:GetService("Players").LocalPlayer
repeat wait() until p.Character
local char = p.Character
local Tool = script.Parent
Tool.Equipped:Connect(function()
for i, v in ipairs(char:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then
if v.Name == "HumanoidRootPart" then
else
v.Transparency = 1
end
for i, v in ipairs(Tool:GetDescendants()) do -- i think ive got this in the wrong place
v.Transparency = 0
end -- end misplaced(?) loop
end
end
end)
Tool.Unequipped:Connect(function()
for i, v in ipairs(char:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then
if v.Name == "HumanoidRootPart" then
else
v.Transparency = 0
end
end
end
end)
Including script samples with your suggestions would be awesome. Thanks!
When looping through the character to make it invisible, you can just check to make sure its not a descendant of the tool itself:
local p = game:GetService("Players").LocalPlayer
repeat wait() until p.Character
local char = p.Character
local Tool = script.Parent
Tool.Equipped:Connect(function()
for i, v in ipairs(char:GetDescendants()) do
if not v:IsDescendantOf(Tool) and (v:IsA("BasePart") or v:IsA("Decal")) then
if v.Name == "HumanoidRootPart" then
else
v.Transparency = 1
end
end
end
end)
Tool.Unequipped:Connect(function()
for i, v in ipairs(char:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then
if v.Name == "HumanoidRootPart" then
else
v.Transparency = 0
end
end
end
end)
Hello there! I see this script is inside the Tool, and in one of the lines, you put:
Tool:GetDescendants())
The loop tries to change every single Instance of the tool to Transparency = 0, but Transparency is not a property of the script, maybe try changing it to Tool:GetChildren()
Or do the following:
for i, v in pairs(Tool:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = 0
end
end
Just realized that this only makes the player invisible to themselves, ie the invisibility isn’t global, which I need it to be.
Changing this from a local to global script hasn’t done anything and keeps the player visible.
Any suggestions?