Fading the Character's Body

Hello there, I’m working on a spawn animation where when your character spawns, it’ll play an animation and during the animation I want all the parts of the character to simultaneously fade in.

Here is my attempt at creating this effect:

– I created a function with the idea that I can run it as many times as I want so it will fade all at once.

local function fade(part)
	for i = 1,0,-0.1 do
		part.Transparency = i
		wait(0.01)
	end
end
  • Here is the rest of the code:
for i,v in pairs(char:GetChildren()) do
			if v:IsA("BasePart") then
				if v.Name ~= "HumanoidRootPart" then
					fade(v)
				end
			end
		end

Right before this I play the animation, which is around 3 - 4 seconds long. And the animation plays fine.

https://gyazo.com/9fbc18ce03faa3faf6fb1d9075289b03

but my issue is:

When I spawn, it fades every body part… one… after… another… Which isn’t what I want.

https://gyazo.com/a92cd973e706b925497a98a8c8c62c72

Have any other ideas / methods that could work?

6 Likes

you should use tweenservice, a much nicer way to do it

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1)

for i,v in pairs(char:GetChildren()) do
	if v:IsA("BasePart") then
		if v.Name ~= "HumanoidRootPart" then
			TS:Create(v, TI, {Transparency = 1})
		end
	end
end
7 Likes

There were a couple things wrong with your code, but I fixed it. Yet it still didn’t work. My character just stayed invisible. No errors in the output.

EDIT: I searched up API and apparently Transparency cannot be tweened? is this correct?

1 Like

Well, either transparency is an attribute or they left it out, because it works fine with mine

2 Likes

Here is what I’ve put, anything look wrong?

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(
	1, 
	Enum.EasingStyle.Linear, 
	Enum.EasingDirection.Out, 
	1
	)

and

	for i,v in pairs(char:GetChildren()) do
			if v:IsA("BasePart") then
				TS:Create(v, TI, {Transparency = 0})
			end
		end
1 Like

You forgot to add :Play()
Change

TS:Create(v, TI, {Transparency = 0})

to

TS:Create(v, TI, {Transparency = 0}):Play()

otherwise it looks fine

Edit: Well, oops, that wan’t you fault, it was mine, I forgot to add it :neutral_face:

3 Likes

Silly me! It worked great! (i haven’t used tweenservice that much sorry !) Thank ! :slight_smile:

1 Like

Transparency is recognized as number value in roblox. Property name is just a way to access the data type. Part.Position is not saved as a data type Position, Part.Position is a reference to a Vector3 stored in memory.

3 Likes

Yeah I thought of that afterwards. Thanks for the clarification! :slight_smile:

1 Like