i want to make a ‘pseudo 3D’ effect by making the character invisible and attaching a part with a SurfaceGui to it. there’s one thing keeping me from moving forward, though: even after setting the transparency of the accessories to 1, they still appear after i reset my character.
what my script currently looks like
-- accessories still just decide to load in. DESPITE me looping through the descendants
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--\\ character setup
local client = Players.LocalPlayer
local currentCam = workspace.CurrentCamera
local originalTransparency = {}
local testPart = workspace:WaitForChild("test-part") -- fake sprite for testing purposes (NOT real)
local connection
--\\ functions
local function toggleItem(target: Model, visible: boolean)
if visible then
print(`making {target} visible`)
for _, descendant in target:GetDescendants() do
if (descendant:IsA("BasePart") or descendant:IsA("MeshPart") or descendant:IsA("Decal")) and originalTransparency[descendant] then
descendant.Transparency = originalTransparency[descendant]
end
end
else
for _, descendant in target:GetDescendants() do
if (descendant:IsA("BasePart") or descendant:IsA("MeshPart") or descendant:IsA("Decal")) then
if originalTransparency[descendant] == nil then
print(`storing the transparency of {descendant}`)
originalTransparency[descendant] = descendant.Transparency
end
descendant.Transparency = 1
print(`transparency set for: {descendant}`)
elseif descendant:IsA("Accessory") then
local handle = descendant:FindFirstChild("Handle")
if handle and handle:IsA("BasePart") then
if originalTransparency[handle] == nil then
print(`storing the transparency of {handle}`)
originalTransparency[handle] = handle.Transparency
end
handle.Transparency = 1
print(`transparency set for: {handle}`)
end
end
end
end
end
local function loadCharacter(char)
-- disconnect existing connection if character respawns
if connection then
connection:Disconnect()
end
local root = char:WaitForChild("HumanoidRootPart")
toggleItem(char, false) -- make character invisible
--\\ runtime (sync camera's y rotation with test part)
connection = RunService.RenderStepped:Connect(function()
local camCFrame = currentCam.CFrame
local _, camYRot, _ = camCFrame:ToEulerAnglesYXZ() -- gimme that y-axis rotation
local partPos = root.Position
-- apply y rotation of the camera to the part, maintaining its position
testPart.CFrame = CFrame.new(partPos) * CFrame.Angles(0, camYRot, 0)
end)
end
--\\ LOAD THIS GOOBER
client.CharacterAdded:Connect(loadCharacter)
if client.Character then -- if character is already loaded (e.g., on the first run), load the character
loadCharacter(client.Character)
end