Script not detecting humanoidrootpart

This is really frustrating, I’m trying to make it so only the humanoidrootpart doesn’t get affected in my script but it just affects it everytime!

local functions = {}

function functions.Start(plr)
	local tweeninfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tweeninfo2 = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local tweenservice = game:GetService("TweenService")
	local chr = plr.Character
	local hum = chr:FindFirstChildOfClass("Humanoid")
	local health = hum.Health
	
	for i, part in pairs(chr:GetDescendants()) do
		if (part:IsA("BasePart") or part:IsA("MeshPart") or part:IsA("Part") and part.Name ~= "HumanoidRootPart") then
			local tween = tweenservice:Create(part, tweeninfo, {Transparency = 1})
			tween:Play()
			part.Material = Enum.Material.Foil
		elseif part:IsA("BillboardGui") then
			part.Enabled = false
		elseif part:IsA("Decal") then
			local tween3 = tweenservice:Create(part, tweeninfo, {Transparency = 1})
			tween3:Play()
		end
	end
	
	hum.HealthChanged:Connect(function(curhealth)
		if hum.Health < health then
			for i, part in pairs(chr:GetDescendants()) do
				if (part:IsA("BasePart") or part:IsA("MeshPart") or part:IsA("Part") and part.Name ~= "HumanoidRootPart") then
					local tween2 = tweenservice:Create(part, tweeninfo2, {Transparency = 0})
					tween2:Play()
					part.Material = Enum.Material.SmoothPlastic
				elseif part:IsA("BillboardGui") then
					part.Enabled = true
				elseif part:IsA("Decal") then
					local tween3 = tweenservice:Create(part, tweeninfo2, {Transparency = 0})
					tween3:Play()
				end
			end
		end
	end)
end

function functions.End(plr)
	local tweenservice = game:GetService("TweenService")
	local tweeninfo2 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local chr = plr.Character
	
	for i, part in pairs(chr:GetDescendants()) do
		if (part:IsA("BasePart") or part:IsA("MeshPart") or part:IsA("Part") and part.Name ~= "HumanoidRootPart") then
			local tween2 = tweenservice:Create(part, tweeninfo2, {Transparency = 0})
			tween2:Play()
			part.Material = Enum.Material.SmoothPlastic
		elseif part:IsA("BillboardGui") then
			part.Enabled = true
		elseif part:IsA("Decal") then
			local tween3 = tweenservice:Create(part, tweeninfo2, {Transparency = 0})
			tween3:Play()
		end
	end
end

return functions

I’d really appreciate some help!

I couldn’t catch what was wrong then I looked closely into your if statement and noticed OR and not AND But it seemed alright then I Looked into BasePart maybe the BasePart segment of the condition could use a

part:IsA("BasePart") and part.Name ~= "HumanoidRootPart"

well, This might not be what’s wrong but it’s the only thing I can guess. I also recommend a little debugging.
Printing everything that is affected under the first conditional.

That sadly didn’t fix it. I searched up “Are meshparts considered baseparts?” and it said they were a form of basepart so I deleted that part and did this:

if (part.Name ~= "HumanoidRootPart" and part:IsA("MeshPart") or part:IsA("Part")) then

yet it still doesn’t work

Well… you kinda recreated the problem
it would be

if (part.Name ~= "HumanoidRootPart" and part:IsA("MeshPart") or part:IsA("Part")  and  part.Name ~= "HumanoidRootPart") then
1 Like

The or is making it not detect the humanoid basepart.
I think you need to do this:

if (part:IsA("BasePart") and part.Name ~= "HumanoidRootPart") then

I think this fixed it! Thank you! but how would i make it so the transparency is 0.5 on the client side?

You would just change the transparency locally within a local script.

1 Like

I will try, thanks for the help.

MeshPart instances and Part instances are both members of the main class “BaseParts” so if a part is a “MeshPart” instance or a “Part” instance then it is inherently a “BasePart” instance, as such you do not need to check for those specific class types (MeshPart and Part) and the conditional statement can be simply changed to the following.

if (part:IsA("BasePart") and part.Name ~= "HumanoidRootPart") then

Yes, I’ve already said that on one of my replies here but thanks for the reply anyways…