I have a loop that loops through every player in the game and sets their parts to invisible via transparency, but when I run through again and set them back to visible, their humanoidrootparts are visible too… I want to keep the script running as is, but I just want the humanoidrootpart to return back to invisible
local hide = true
local orignalTransparency = {}
local function checkPart(part)
for a,b in pairs(part:GetChildren()) do
checkPart(b)
end
if part:IsA("BasePart") or part:IsA("Decal") and not part:IsA("HumanoidRootPart") then
if hide then
if not orignalTransparency[part] then
orignalTransparency[part] = part.Transparency
end
part.Transparency = 0
else
if orignalTransparency[part] then
part.Transparency = orignalTransparency[part]
orignalTransparency[part] = nil
end
end
end
end
EDIT: oops I did what you told me wrong… I just realized lol
wait is HumanoidRootPart an actual class? (Omg this is the best day ever)
From looking at your code it seems right except you might want to do this instead:
if (part:IsA("BasePart") or part:IsA("Decal")) and not part:IsA("HumanoidRootPart") then
When it comes to if statements and using or’s and using an and, its best to put the OR stuff into the () that way it doesnt act silly
This didn’t seem to work for some reason, no errors in the output either. Do you think it would be easier to loop back through the players again after the other script has run to set the HumanoidRootPart’s transparencies to invisible again?
As far as I know, HumanoidRootPart isn’t an actual class, so you cannot use :IsA() to check if a part is an HRP. You will have to check if the name of the part isn’t “HumanoidRootPart” instead. Something like part.Name ~= "HumanoidRootPart".
I’m frying my brain, I am defo doing something wrong still haha
local function checkPart(part)
for a,b in pairs(part:GetChildren()) do
checkPart(b)
end
if (part:IsA("BasePart") or part:IsA("Decal")) and not part.Name == "HumanoidRootPart" then
if hide then
if not orignalTransparency[part] then
orignalTransparency[part] = part.Transparency
end
part.Transparency = 1
else
if orignalTransparency[part] then
part.Transparency = orignalTransparency[part]
orignalTransparency[part] = nil
end
end
end
end
I would recommend wrapping part.Name == "HumanoidRootPart" in parentheses like so. … and not (part.Name == "HumanoidRootPart") then
Or you can simply do this: … and part.Name ~= "HumanoidRootPart" then
The HumanoidRootPart (HRP), is just a regular BasePart that roblox’s engine (from my understanding) uses to position, move, and animate the character. You arent able to use IsA for this because it is not some special instance, just a regular ol’ brick.
Maybe try to reference the HRP from the humanoid instance’s Humanoid.RootPart property, or use Character.PrimaryPart.
local function checkPart(part)
for a,b in pairs(part:GetChildren()) do
checkPart(b)
end
if (part:IsA("BasePart") or part:IsA("Decal")) and not (part == Humanoid.RootPart or part == Character.PrimaryPart) then
if hide then
if not orignalTransparency[part] then
orignalTransparency[part] = part.Transparency
end
part.Transparency = 1
else
if orignalTransparency[part] then
part.Transparency = orignalTransparency[part]
orignalTransparency[part] = nil
end
end
end
end
local char = game.Players.LocalPlayer.Character
local humanoid = char:FindFirstChildOfClass("Humanoid")
local function check()
if char then
for _, v in pairs(char:GetChildren()) do
if (v:IsA("BasePart") or v:IsA("Decal")) and not (v == humanoid.RootPart or v == char.PrimaryPart) then
print(v.Name.." is not the HRP")
elseif (v:IsA("BasePart") or v:IsA("Decal")) and (v == humanoid.RootPart or v == char.PrimaryPart) then
print(v.Name.." is the HRP")
end
end
end
end
check()
Output:
10:22:54.170 Head is not the HRP - Client - LocalScript:8
10:22:54.170 Torso is not the HRP - Client - LocalScript:8
10:22:54.170 Left Arm is not the HRP - Client - LocalScript:8
10:22:54.170 Right Arm is not the HRP - Client - LocalScript:8
10:22:54.171 Left Leg is not the HRP - Client - LocalScript:8
10:22:54.171 Right Leg is not the HRP - Client - LocalScript:8
10:22:54.171 HumanoidRootPart is the HRP - Client - LocalScript:10
Here is how I applied it to mine, if I even did it correctly haha.
I should have done this a while ago, but this is the entire script, I didn’t think it was needed with my original question…
local hide = true
local orignalTransparency = {}
local char = game.Players.LocalPlayer.Character
local humanoid = char:FindFirstChildOfClass("Humanoid")
local function checkPart(part)
if char then
for _, v in pairs(char:GetChildren()) do
if (v:IsA("BasePart") or v:IsA("Decal")) and not (v == humanoid.RootPart or v == char.PrimaryPart) then
if hide then
if not orignalTransparency[part] then
orignalTransparency[part] = part.Transparency
end
part.Transparency = 1
else
if orignalTransparency[part] then
part.Transparency = orignalTransparency[part]
orignalTransparency[part] = nil
end
end
end
end
end
end
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
game:GetService("RunService").RenderStepped:Connect(function()
for i,v in pairs(players:GetPlayers()) do
if v ~= localPlayer then
local char = v.Character
if char then
checkPart(char)
end
end
end
for part,trans in pairs(orignalTransparency) do
if not part then
orignalTransparency[part] = nil
elseif not part.Parent then
orignalTransparency[part] = nil
end
end
end)
local PlayerService = game:GetService("Players")
local RunService = game:GetService("RunService")
local localPlayer = PlayerService.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local toHide = true
local orignalTransparency = {}
local function CheckPart(character :Model)
for _, part in character:GetChildren() do
if part.Name == "HumanoidRootPart" then continue end --This answears your main question
if part:IsA("BasePart") or part:IsA("Decal") then
if toHide then
if not orignalTransparency[part] then
orignalTransparency[part] = part.Transparency
end
part.Transparency = 1
else
if orignalTransparency[part] then
part.Transparency = orignalTransparency[part]
orignalTransparency[part] = nil
end
end
end
end
end
RunService.RenderStepped:Connect(function()
for _, player in PlayerService:GetPlayers() do
if player ~= localPlayer then
local character = player.Character
if character then
CheckPart(character)
end
end
end
for part, transparency in orignalTransparency do
if not part then
orignalTransparency[part] = nil
elseif not part.Parent then
orignalTransparency[part] = nil
end
end
end)
print("Hiding!")
task.wait(23)
toHide = not toHide
print("Appear!")
Hm, fair point. Maybe just not use the Character.PrimaryPart then I guess and just stick to Humanoid.RootPart. I’d also say the RootPart property is fool proof because a humanoid REQUIRES a RootPart in the first place to even do anything, unless I haven’t caught up onto some news about humanoids .