Help making NPC freeze upon death + fade away

Hi, I was thinking of making a script that freezes a NPC humanoid’s position upon death as well as it fading away. I have a rough draft and idea of the outline of the script below. I have no scripting capabilities which is why I need help from someone to make my script function

script.Parent.Humanoid.Died:Connect(function()
if Humanoid.health <= 0 then

Humanoid.Anchored = true

wait(0.1)
Humanoid.Transparency(0.1)
wait(0.1)
Humanoid.Transparency(0.2)
wait(0.1)
Humanoid.Transparency(0.3)
wait(0.1)
Humanoid.Transparency(0.4)
wait(0.1)
Humanoid.Transparency(0.5)
wait(0.1)
Humanoid.Transparency(0.6)
wait(0.1)
Humanoid.Transparency(0.7)
wait(0.1)
Humanoid.Transparency(0.8)
wait(0.1)
Humanoid.Transparency(0.9)
wait(0.1)
Humanoid.Transparency(1)

end
end)
2 Likes

Have a look at TweenService, it’s pretty useful :wink:

2 Likes

I Think health needs a capital h if I’m not mistaken

this script seems perfectly fine except for the fact that humanoid doesn’t have a transparency thing, im not the best script and the following code probably could be cleaned up a bit but…

local visible = 0
script.Parent.Humanoid.Died:Connect(function()
if script.Parent.Humanoid.health <= 0 then
local NPC = script.Parent
NPC.Anchored = true
local H = NPC.Head.Transparency
local UT = NPC.UpperTorso.Transparency
local LT = NPC.LowerTorso.Transparency
local URA = NPC.UpperRightArm.Transparency
local LRA = NPC.LowerRightArm.Transparency
local RH = NPC.RightHand.Transparency
local ULA = NPC.UpperLeftArm.Transparency
local LLA = NPC.LowerLeftArm.Transparency
local LH = NPC.LeftHand.Transparency
local URL = NPC. UpperRightLeg.Transparency
local LRL = NPC.LowerRightLeg.Transparency
local RF = Npc.RightFoot.Transparency
local ULL = NPC.UpperLeftLeg..Transparency
local LLL = NPC.LowerLeftLeg.Transparency
local LF = NPC. LeftFoot.Transparency
repeat
 H = visible
UT = visible
LT = visible
URA = visible
LRA = visible
RH = visible
ULA = visible
LLA = visible
LH = visible
URL = visible
LRL = visible
RF = visible
ULL = visible
LLL = visible
LF = visible
visible = visible + 0.1
wait(.1)
until visible == 1
NPC:remove()
end
end)

i’d also like to stress that you cant anchor humanoid, It more just makes the model a living thing.
also this is a very VERY messy script that could be far better somebody please make it nice. there are also better ways to do this other than my elementary knowlesge of coding

The player’s humanoid doesn’t have an Anchored or Transparency property since those properties are only inherited by members of the BasePart class.

script.Parent.Humanoid.Died:Connect(function()
	for i = 0, 1, 0.01 do
		for _, part in ipairs(script.Parent:GetDescendants()) do
			if (part:IsA("BasePart")) then
				part.Anchored = true
				-- I do this instead of just setting transparency to i to account for parts that may already be invisible.
				part.Transparency = part.Transparency + i
			end
		end
		game:GetService("RunService").Heartbeat:Wait()
	end
end)
5 Likes

TweenService can be really helpful in this case so that wouldn’t have to write 40 lines of just changing transparency. Also the humanoid doesn’t have a transparency property so you have to loop through all the parts in the player. Here’s what the code would look like:

character.HumanoidRootPart.Anchored = true
for i, v in pairs(character:GetDescendants()) do
    if v:IsA'BasePart' then
          TweenService:Create(v, TweenInfo.new(timeInSeconds),  {Transparency = 1}):Play()
    end
end
2 Likes

Coughs… Seriously do what this guy said though, it’s far FAR better than mine. From garbage scripter to scripter. always listen to people with the Programmer flair

maybe not always

2 Likes

Thanks, this really helped!
https://gyazo.com/93256babcd5ac17d4c7e70d0876c29fc

1 Like

This helped a lot, thanks for introducing tweenservice, I didn’t know what that was before.

1 Like