A while back I needed help with a tool that makes the player invisible, but not the tool itself. While the solution worked like a charm, we discovered in multiplayer testing that the player’s invisibility isn’t global, meaning while you can’t see yourself when holding the tool, other players can.
I figured it was an issue of the invisibility script being a LocalScript, but it seems that wasn’t the case, and changing it to a normal Script broke it.
Here is the script as it currently is:
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)
Including script samples with your suggestions would be awesome. Thanks!
The client has a neat feature to detect the player’s game.Players.LocalPlayer` where the server requires a few different ways for different scenarios which I’ve listed all down below.
• Remote Functions
To keep the script small and clean use Remote Functions. These can be invoked through client or server scripts and the other side will carry it out as an ordinary function. It’ll always send the player as its first argument therefore you have its character.
• Tool Parent
Another simple way to detect the character is through the parent of the tool. If the player equips a tool the tool’s parent will always be the character of the player. Simply use the tool. Parents to find character easily.
Additionally using plr.CharacterAdded:Connect(function(char) you can use a child detector to see if a tool is added and what the name is. If it matches the profile you’re looking for you can run a function if activated.
These are the main methods I would use for an invisible tool globally.
I’ll be using the remote function method, but before we start we’ll be creating all the needed elements.
Add a remote function to ReplicatedStorage
Name it: HidePlayer
Create a LocalScript
Parent must be tool
Create a Script
Parent must be ServerScriptService / Tool
Client - Sided
Inside the LocalScript we’re going to be invoking the function.
Variables:
local Remote = game.ReplicatedStorage.HidePlayer
local Tool = script.Parent
local Player = game.Players.LocalPlayer
Functions:
Tool.Equipped:Connect(function()
Remote:InvokeServer(true) -- True means invisible
end)
Tool.Unequipped:Connect(function()
Remote:InvokeServer(false) -- False means visible
end)
Server - Sided
Variables:
local Remote = game.ReplicatedStorage.HidePlayer
Functions:
Remote.OnServerInvoke = function(plr, state)
if state then -- Invisible
for _,obj in pairs(plr.Character:GetDescendants()) do
if obj:IsA("BasePart") or obj:IsA("Decal") then
if obj.Name ~= "HumanoidRootPart" and not obj:FindFirstAncestorWhichIsA("Tool") then -- Checks HRP and tool.
obj.Transparency = 1
end
end
end
else -- Visible
for _,obj in pairs(plr.Character:GetDescendants()) do
if obj:IsA("BasePart") or obj:IsA("Decal") then
if obj.Name ~= "HumanoidRootPart" and not obj:FindFirstAncestorWhichIsA("Tool") then -- Checks HRP and tool.
obj.Transparency = 0
end
end
end
end
end