The way you are doing it is not efficient. You should instead use TweenService.
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
2, -- Duration of the tween
Enum.EasingStyle.Linear, -- Easing style
Enum.EasingDirection.Out, -- Easing direction
0, -- how many times it repeats
false, -- if it should reverse
0 -- delay if the animation is repeating
)
script.Parent.Humanoid.Died:Connect(function()
print("lol dead")
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
local tween = TweenService:Create(v, tweenInfo, {Transparency = 1})
tween:Play()
end
end
end)
I would recommend you use the TweenService to do this. Since this will allow you to apply a tween to all of the body parts and allow them to be syncronized.
Well, when the character is respawning after it dies, all the model itself is respawning, including the script. Try to make the time to fully change the transparency of all the body parts shorter than the time it takes for the character to respawn. Also, it is better to use TweenService as @xZylter and @BPilot253 said.
script.Parent.Humanoid.Died:Connect(function()
print("lol dead")
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
local tweenService = game:GetService("TweenService");
local tweenInfo = TweenInfo.new(
game:GetService("Players").RespawnTime - 1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out
)
local goal = {
Transparency = 1;
}
local finalTween = tweenService:Create(v, tweenInfo, goal)
finalTween:Play()
end
end
end)