LocalTransparencyModifier variable switching

Currently I’m using a switch bool to change how I want my LocalTransparencyModifier to be modified.

Code here.

local doGunTransparency,doCardTransparency = false,false
local tool = false

for i,v in pairs(c:GetChildren()) do
	if v:IsA("BasePart") and v.Name ~= "Head" then
		v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
			if tool == true and doGunTransparency == true or tool == true and doCardTransparency == true or tool == true and doCardTransparency == true and doGunTransparency == true then
				if v.Name ~= "RightUpperArm" and v.Name ~= "RightLowerArm" and v.Name ~= "RightHand" and v.Name ~= "LeftUpperArm" and v.Name ~= "LeftLowerArm" and v.Name ~= "LeftHand" then
					if tool == true then
						v.LocalTransparencyModifier = 0
					end
				else
					if tool == true then
						v.LocalTransparencyModifier = 1
					else
						v.LocalTransparencyModifier = 0
					end
				end
			elseif not tool or not doGunTransparency or not doCardTransparency then
				v.LocalTransparencyModifier = 0
			end
		end)
		v.LocalTransparencyModifier = 0
	end
end

(Ignore the sloppiness, its temporary before I rewrite it.)

variable “c” being the character in this code.

Now the issue is, its fine at first after switching to true and turning off the arms, but after that it just stays arms transparent. I even made sure that it was being set to false and when printing each side of the main if statement it prints as it should, but the transparency doesn’t follow the same “as it should” functionality.

All of this stuff is done over the client with my viewmodel controller sending a BindableEvent remote to toggle the 3 bool variables set in the code above. (Basically what triggers the on and off switch for the arm transparency thing.)

It doesn’t need to be replicated to server because this is a single player game so most stuff can be done on the client with a few exceptions.

Does anyone know why this could be happening? I don’t usually mess with LocalTransparency since I don’t usually need to.

Any input is appreciated.

Thanks

1 Like

Boosting post since its been a bit

1 Like

This looks past my skill level but I’m going to try anyways, maybe I will learn something out of it myself.

I kept looking at this part:

    if tool == true then
		v.LocalTransparencyModifier = 0
	end
else
	if tool == true then
		v.LocalTransparencyModifier = 1
	else
		v.LocalTransparencyModifier = 0
	end

This tells me you check if the tool value is equal to true, then turn visible, but then you check again if the value of tool is equal to true, turning it transparent, which is where it gets stuck.

Maybe this will work?

    if tool == true then
		v.LocalTransparencyModifier = 0
	end
else
		v.LocalTransparencyModifier = 1
	end

If that does not work, you can try printing tool, doGunTransparency and doCardTransparency right before the last elseif to check if they meet all the requirements to turn visible again.

I tried removing that before and also printing that stuff, it returns everything as it should be for this to function correctly.

I am so confused.