Why does the HumanoidRootPart Become Visible

So i am making a one piece game with Devil-fruits. I am currently working on Suke no mi, witch gives you the ability to become invisible. for you who don’t know what an devil fruit is it´s basically a fruit that gives abilities/magic.

The Logic:

I transform the bodyParts and decals transparency to 0 after the invisible time or the player got dameged but the HumanoidRootPart is getting 0 as transparency. I made a if statement in line () and () that it should ignore HumanoidRootPart. Because i dont want the HumanoidRootPart to be visible.

This is the local script, located in player scripts.

local SukeRemote = game.ReplicatedStorage.FireClientEvent
local InvisibleTime = 20

	SukeRemote.OnClientEvent:Connect(function(plr,AttackE)

	if AttackE == "AttackE" then
	
	print("RenderSuke AttackE")
	
	local c = plr.Character
	local Humanoid = c:FindFirstChild("Humanoid")

	
    for i, v in ipairs(c:GetDescendants()) do
		if v:IsA("BasePart") or v:IsA("Decal") then
			
			local Info = TweenInfo.new(2)
			local Tween = game:GetService("TweenService"):Create(v,Info,{Transparency=1})
			Tween:Play()	    
				
				
	end
	end
	
	local OldHealth = Humanoid.Health
	Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
		OldHealth = Humanoid.Health
	end)

    Humanoid:GetPropertyChangedSignal("Health"):Connect(function()

		if Humanoid.Health < OldHealth then

			for i, v in ipairs(c:GetDescendants()) do
				local PrevV = v.Name
				if v:IsA("BasePart") or v:IsA("Decal") and  v.Name ~= "HumanoidRootPart"  and v.Name ~= PrevV  then -- Heres the problem. i transform the body and decals transparency to 0 -----again, but the humanoid root part still gets it´s transparency to 0.
					local Info = TweenInfo.new(2)
					local Tween = game:GetService("TweenService"):Create(v,Info,{Transparency=0})
					Tween:Play()
				
					



				end
			end

		end

	end)

	
	wait(InvisibleTime)
	
	for i, v in ipairs(c:GetDescendants()) do
		local PrevV = v.Name
		if v:IsA("BasePart") or v:IsA("Decal") and v.Name ~= "HumanoidRootPart" and v.Name ~= PrevV then
            local Info = TweenInfo.new(2)
			local Tween = game:GetService("TweenService"):Create(v,Info,{Transparency=0})
			Tween:Play()

		

			

    end
	end
	
	
	
	
   	end
   	end)
  1. What is the issue? Include screenshots / videos if possible!

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

the problem is your or statement, it should be:

if (v:IsA("BasePart") or v:IsA("Decal")) and  v.Name ~= "HumanoidRootPart"  and v.Name ~= PrevV  then

what is the different ???

the HumanoidRootPart would be transparent by default.

if v:IsA("BasePart") or v:IsA("Decal") and v.Name ~= "HumanoidRootPart" then
	local Info = TweenInfo.new(2)
	local Tween = game:GetService("TweenService"):Create(v,Info,{Transparency=1})
	Tween:Play()	
end

You could replace

v.Name ~= "HumanoidRootPart"

with

v ~= Humanoid.RootPart

Also you are never disconnecting your Humanoid.HealthChanged events (This wouldn’t be a problem if Roblox called Destroy() on the Character after death, which it doesn’t).

Try doing this:

for i, v in ipairs(c:GetDescendants()) do
	local PrevV = v.Name
	if v:IsA("BasePart") or v:IsA("Decal") then 
        if v.Name == "HumanoidRootPart" or v.Name == PrevV then continue end
		local Info = TweenInfo.new(2)
		local Tween = game:GetService("TweenService"):Create(v,Info,{Transparency=0})
		Tween:Play()
	end
end
1 Like

It’s almost like math, bracket comes before the rest so the if statement looks at the bracket first

1 Like

What does the extra brackets do. ???

This is how the script would interpret your current if statement:

  1. Is “v” a “BasePart”? (if so proceed)
  2. Is “v” a “Decal” AND is “v”'s name not “HumanoidRootPart” AND is “v”'s name not Prevv? (if so proceed)

This means that since “v” is already a “BasePart”, it will proceed and the HumanoidRootPart is a “BasePart”

ohh ok so it prioritise thats inside the extra brackets very first. thanks :smiley:

Okay, let’s do some big brains here. You know, in mathematics, different operators(+, -, *, /, etc.) have precedence. This means if something is like this: 2 + 1 * 8, first 1 will be multiplied by eight then added into two, thus making the answer ten instead of something like 24. It is the same with logical operators(and, or, not). First comes the logical not with the highest precedence, then logical and , and at last logical or. Putting brackets just makes sure that stuff is done in the right sequence.

1 Like