Why does my game crash when I change the LocalTransparencyModifier to 0?

if not game:IsLoaded() then game.Loaded:Wait() end

local player = game.Players.LocalPlayer
local character = player.Character

local armPrefix = "Right Arm"

local function setLocalTransparency(object: BasePart, transparencyValue: number)
	assert(object:IsA("BasePart"))
	
	object.LocalTransparencyModifier = transparencyValue
	
	object:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
		object.LocalTransparencyModifier = transparencyValue
	end)
end

local function resetCharacterInfo(v: Instance)
	if v:IsA("BasePart") then
		setLocalTransparency(v, 1)
	end
end

local function setCharacterInfo(v: Instance)
	if v:IsA("BasePart") and v.Name:find(armPrefix) then
		setLocalTransparency(v, 0)
	end
end

local function onResetView()
	for _, v in character:GetChildren() do
		resetCharacterInfo(v)
	end
end

local function onViewArm()
	for _, v in character:GetChildren() do
		setCharacterInfo(v)
	end
end

for _, v: Tool in player.Backpack:GetChildren() do
	v.Equipped:Connect(function()
		onViewArm()
	end)
	
	v.Unequipped:Connect(function()
		onResetView()
	end)
end
``` The issue happens right after the Unequipped event is fired.

the issue is because it’s in infinite loop which was causing the game to crash

object:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
    object.LocalTransparencyModifier = transparencyValue
end)
if not game:IsLoaded() then game.Loaded:Wait() end

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local armPrefix = "Right Arm"

local function setLocalTransparency(object: BasePart, transparencyValue: number)
    assert(object:IsA("BasePart"))
    
    if object.LocalTransparencyModifier ~= transparencyValue then
        object.LocalTransparencyModifier = transparencyValue
    end
end

local function resetCharacterInfo(v: Instance)
    if v:IsA("BasePart") then
        setLocalTransparency(v, 1)
    end
end

local function setCharacterInfo(v: Instance)
    if v:IsA("BasePart") and v.Name:find(armPrefix) then
        setLocalTransparency(v, 0)
    end
end

local function onResetView()
    for _, v in character:GetChildren() do
        resetCharacterInfo(v)
    end
end

local function onViewArm()
    for _, v in character:GetChildren() do
        setCharacterInfo(v)
    end
end

for _, v: Tool in player.Backpack:GetChildren() do
    v.Equipped:Connect(function()
        onViewArm()
    end)
    
    v.Unequipped:Connect(function()
        onResetView()
    end)
end

should solve the issue if there’s error let me know

i see but if i remove changed function, the systeme is not work for me

we can defer it

if not game:IsLoaded() then game.Loaded:Wait() end

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local armPrefix = "Right Arm"

local function setLocalTransparency(object: BasePart, transparencyValue: number)
    assert(object:IsA("BasePart"))
    
    local function updateTransparency()
        if object.LocalTransparencyModifier ~= transparencyValue then
            object.LocalTransparencyModifier = transparencyValue
        end
    end
    
    updateTransparency()
    
    local connection
    connection = object:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
        task.defer(function()
            if connection.Connected then
                updateTransparency()
            end
        end)
    end)
end

local function resetCharacterInfo(v: Instance)
    if v:IsA("BasePart") then
        setLocalTransparency(v, 1)
    end
end

local function setCharacterInfo(v: Instance)
    if v:IsA("BasePart") and v.Name:find(armPrefix) then
        setLocalTransparency(v, 0)
    end
end

local function onResetView()
    for _, v in character:GetChildren() do
        resetCharacterInfo(v)
    end
end

local function onViewArm()
    for _, v in character:GetChildren() do
        setCharacterInfo(v)
    end
end

for _, v: Tool in player.Backpack:GetChildren() do
    v.Equipped:Connect(function()
        onViewArm()
    end)
    
    v.Unequipped:Connect(function()
        onResetView()
    end)
end

this should solve the issue if it crash’s let me know