How would I slowly fade a players character?

I have this tween service that moves the character up in the air, and I want them to slowly become invisible as they move. How could I do this?

local tweenInfo = TweenInfo.new(
	3,
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local tween = TweenService:Create(char.HumanoidRootPart, tweenInfo, { Position = char.HumanoidRootPart.Position + Vector3.new(0, 10, 0) })

tween:Play()
		
tween.Stopped:Connect(function()
	plr:LoadCharacter()
end)

You can iterate over the character’s descendants.

local ts = game:GetService("TweenService")
local tweens = {}

local function cleanup()
    for _, tween in next, tweens, nil do
        tween:Destroy()
    end
end

--then:
for _, part in next, char:GetDescendants(), nil do
    if not v:IsA("Part") and not v:IsA("MeshPart") then continue end
    local tween = ts:Create(v, tweenInfo, {Transparency = 1})
    tween:Play()
    table.insert(tweens, tween)
end

cleanup()
1 Like

These tweens would be destroyed as soon as the loop ends. Also, tweens remove themselves if there are no references to them when they finish.

TimeToTween = 3
local tweenInfo = TweenInfo.new(
	TimeToTween ,
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
function MakeYouFade(Character)
	--//I'd reccomend using a BodyMover constraint (like linearvelocity) instead of tweening the player upwards. But if you need to for whatever reason, you should anchor the rootpart first.

	for i,v in ipairs(Character:GetDescendants()) do
		if v:IsA("BasePart") then
			--//Make parts invisible.
			tween = TweenService:Create(char.HumanoidRootPart, tweenInfo, { Transparency = 1})

			tween:Play()
		end
	end
	task.wait(TimeToTween)
	plr:LoadCharacter()
end
1 Like

Oops, I forgot to wait the tween time. Thanks for the correction. Are you sure they remove themselves? I’ve used tweens and checked memory logs, etc. afterwards and they’ve still existed.

As long as they aren’t parented and don’t have any other references, they should be cleaned up like any other instance.

Thanks for the help, for some reason, the player doesn’t fade. Any ideas why?

local description = game:GetService("ServerStorage").GodlyCharacter
		humanoid:ApplyDescriptionReset(description)
		
		local TimeToTween = 3
		local tweenInfo = TweenInfo.new(
			TimeToTween ,
			Enum.EasingStyle.Linear, -- EasingStyle
			Enum.EasingDirection.Out, -- EasingDirection
			0, -- RepeatCount (when less than zero the tween will loop indefinitely)
			false, -- Reverses (tween will reverse once reaching it's goal)
			0 -- DelayTime
		)
		
		local function MakeYouFade(Character)
			--//I'd reccomend using a BodyMover constraint (like linearvelocity) instead of tweening the player upwards. But if you need to for whatever reason, you should anchor the rootpart first.

			for i,v in ipairs(Character:GetDescendants()) do
				if v:IsA("BasePart") then
					--//Make parts invisible.
					local tween = TweenService:Create(char.HumanoidRootPart, tweenInfo, { Transparency = 1})

					tween:Play()
				end
			end
			task.wait(TimeToTween)
			plr:LoadCharacter()
		end
		
		local tween = TweenService:Create(char.HumanoidRootPart, tweenInfo, { Position = char.HumanoidRootPart.Position + Vector3.new(0, 10, 0) })

		tween:Play()
		
		MakeYouFade(char)

Edit: I was being stupid I just had to swap char.HumanoidRootPart for v. Thank you very much for your help its working perfectly

local description = game:GetService("ServerStorage").GodlyCharacter
humanoid:ApplyDescriptionReset(description)

local TimeToTween = 3
local tweenInfo = TweenInfo.new(
	TimeToTween ,
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local function MakeYouFade(Character)
	--//I'd reccomend using a BodyMover constraint (like linearvelocity) instead of tweening the player upwards. But if you need to for whatever reason, you should anchor the rootpart first.

	for i,v in ipairs(Character:GetDescendants()) do
		if v:IsA("BasePart") then
			--//Make parts invisible.
			local tween = TweenService:Create(v, tweenInfo, { Transparency = 1})

			tween:Play()
		end
	end
	task.wait(TimeToTween)
	plr:LoadCharacter()
end

local tween = TweenService:Create(char.HumanoidRootPart, tweenInfo, { Position = char.HumanoidRootPart.Position + Vector3.new(0, 10, 0) })

tween:Play()

MakeYouFade(char)

EDIT: Nevermind, you figured it out on your own. Still, I’ll leave it here for anyone else needing this.

1 Like

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