After making the player's arms visible in first person, I can't revert them back to invisible

I have this function in my localscript to make the player’s arms visible before performing an animation. I want to make it so the arms will go back to being invisible after a while like .5 second. But I can’t get it to work.

local function makeArmsVisible(part)
	if part and part:IsA("BasePart") and(part.Name=="LeftUpperArm"  or part.Name=="LeftLowerArm" or part.Name=="LeftHand" or part.Name=="RightUpperArm" or part.Name=="RightLowerArm" or part.Name=="RightHand" or part.Name=="Left Arm" or part.Name=="Right Arm") then
		part.LocalTransparencyModifier = part.Transparency
		part.Changed:Connect(function(property)
			part.LocalTransparencyModifier = part.Transparency
		end)
	end
end
3 Likes
local function makeArmsVisible(part)
	if part and part:IsA("BasePart") and(part.Name=="LeftUpperArm"  or part.Name=="LeftLowerArm" or part.Name=="LeftHand" or part.Name=="RightUpperArm" or part.Name=="RightLowerArm" or part.Name=="RightHand" or part.Name=="Left Arm" or part.Name=="Right Arm") then
		part.LocalTransparencyModifier = part.Transparency
		part:GetPropertyChangedSignal("Transparency"):Connect(function()
			part.LocalTransparencyModifier = part.Transparency
		end)
	end
end
3 Likes

on line 5 it’s not Transparency but LocalTransparencyModifier. Your code normally breaks it since LocalTransparencyModifier is what makes the body invisible client side. But I need a function to make it INVISIBLE not visible. My code already worked for making it visible. I just can’t find a way to revert it back to invisible

2 Likes

put a task.wait(.5) after the first loop, then loop through them again to make them invisible.

1 Like

I tried doing that, it didn’t work. I’m assumign it’s because part.changed is connected to changing the localtransparencymodifier value which is 1 to the server side transparency value of the part which is 0. idk how to fix that

1 Like

Maybe create a second local function like this:

local OriginalTransparency = {} -- Table to store original transparency values

local function makeArmsVisible(part)
	if part and part:IsA("BasePart") and (part.Name == "LeftUpperArm" or part.Name == "LeftLowerArm" or part.Name == "LeftHand" or part.Name == "RightUpperArm" or part.Name == "RightLowerArm" or part.Name == "RightHand" or part.Name == "Left Arm" or part.Name == "Right Arm") then
		if not OriginalTransparency[part] then
			OriginalTransparency[part] = part.Transparency
		end
		
		part.LocalTransparencyModifier = part.Transparency
		
		part.Changed:Connect(function(property)
			part.LocalTransparencyModifier = part.Transparency
		end)
	end
end

local function makeArmsInvisible(part)
	if part and part:IsA("BasePart") then
		if OriginalTransparency[part] then
			part.LocalTransparencyModifier = OriginalTransparency[part]
		else
			part.LocalTransparencyModifier = 1 -- Set to fully transparent if no original transparency is stored
		end
	end
end

1 Like

Chatgpt gave the same result but it doesn’t work. With no errors whatsoever. I think the reason is that it only sets it once but the other function keeps setting it every frame since normally roblox automatically sets the localtransparencymodifier of body parts to 1 every frame if they’re modified. the first function prevents that by connecting part.Changed to the code that sets the localtransparencymodifier to 0. I don’t know how to revert having connected part.Changed to changing it every frame.

1 Like

I finally found what I was looking for while messing around. It’s :Disconnect(). I made a table to hold all the RbxScriptConnections for each part and later on in the MakeArmsInvisible function I made a for loop to go through each connection in the table and used :Disconnect(). I’ll post the code below in case anyone else reading this in the future has the same issue.

local Connections = {}

local function makeArmsVisible(part)
	if part and part:IsA("BasePart") and(part.Name=="LeftUpperArm"  or part.Name=="LeftLowerArm" or part.Name=="LeftHand" or part.Name=="RightUpperArm" or part.Name=="RightLowerArm" or part.Name=="RightHand" or part.Name=="Left Arm" or part.Name=="Right Arm") then
		part.LocalTransparencyModifier = part.Transparency
		visibleConnection = part.Changed:Connect(function(property)
			part.LocalTransparencyModifier = part.Transparency
		end)
		table.insert(Connections, visibleConnection)
	end
end

local function makeArmsInvisible(part)
	if part and part:IsA("BasePart") and (part.Name == "LeftUpperArm" or part.Name == "LeftLowerArm" or part.Name == "LeftHand" or part.Name == "RightUpperArm" or part.Name == "RightLowerArm" or part.Name == "RightHand" or part.Name == "Left Arm" or part.Name == "Right Arm") then
		for _, connection in ipairs(Connections) do
			connection:Disconnect()
		end
		part.LocalTransparencyModifier = 1
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.