Child is not a valid member of character after they die?
I have this here script that is supposed to grab players when the vampire player touches them while in beast mode. But the problem is that when a player dies (grabbed player or vampire player) the script starts bugging out and saying that the child of the character is not valid. Any way to work around this?
pictures of errors
001 | local grabblock = script.Parent.Torso |
002 | local vampchar = script.Parent |
003 | local vampplayer = game.Players:GetPlayerFromCharacter(vampchar) |
004 | local BeastEvent = game.ReplicatedStorage.Events.BeastMode |
006 | local players = game:GetService( "Players" ) |
007 | if vampchar.charactervalues:WaitForChild( "Role" ).Value ~ = "Vampire" then |
008 | script.Disabled = true |
010 | grabblock.Touched:Connect( function (v 1 ) |
012 | local v 3 = players:GetPlayerFromCharacter(v 2 ) |
013 | if vampchar:FindFirstChild( "charactervalues" ).Grabbing.Value = = true then return end |
014 | if v 2 :FindFirstChild( "Humanoid" ) then |
015 | if vampchar.charactervalues.BeastMode.Value = = true and v 2. charactervalues.Role.Value ~ = "Vampire" and vampchar.charactervalues.Grabbing ~ = true and v 2. Humanoid.Health ~ = 0 and ( not v 2 :FindFirstChild( "FF" )) and (v 2. charactervalues.Grabbed.Value ~ = true ) then |
019 | vampchar.Humanoid:LoadAnimation(script.Grab):Play() |
020 | vampchar.charactervalues.Grabbing.Value = true |
022 | v 2. charactervalues.Grabbed.Value = true |
026 | local bsound = game.ServerStorage.CaughtSnd:Clone() |
027 | bsound.Parent = vampchar.HumanoidRootPart |
028 | bsound.Playing = true |
033 | local screamnum = math.random( 1 , 2 ) |
034 | if screamnum = = 1 then |
035 | local scream 1 = game.ServerStorage.Scream 1 :Clone() |
036 | scream 1. Parent = v 2 :FindFirstChild( "HumanoidRootPart" ) |
037 | scream 1. Playing = true |
042 | elseif screamnum = = 2 then |
043 | local scream 2 = game.ServerStorage.Scream 2 :Clone() |
044 | scream 2. Parent = v 2 :FindFirstChild( "HumanoidRootPart" ) |
045 | scream 2. Playing = true |
052 | local moveto = game.ServerStorage.GrabWeld:Clone() |
053 | moveto.Parent = vampchar |
054 | moveto.Attachment 0 = v 2. Torso.GrabAttatch |
055 | moveto.Attachment 1 = vampchar.Torso.GrabAttatch |
057 | vampchar.charactervalues.BeastMode.Changed:Connect( function () |
058 | if vampchar.charactervalues.BeastMode.Value = = false and vampchar.charactervalues.Grabbing.Value = = true then |
059 | v 2. charactervalues:WaitForChild( "Grabbed" ).Value = false |
067 | local progress = v 2. charactervalues:WaitForChild( "EscapeProgress" ) |
068 | local grabbed = v 2. charactervalues:WaitForChild( "Grabbed" ) |
070 | local grabbing = vampchar.charactervalues:WaitForChild( "Grabbing" ) |
072 | local beast = vampchar.charactervalues:WaitForChild( "BeastMode" ) |
073 | local anim = v 2. Humanoid:LoadAnimation(script.Escape) |
074 | progress.Changed:Connect( function () |
075 | if progress.Value = = 100 and grabbed.Value = = true then |
077 | local ff = Instance.new( "ForceField" ) |
086 | grabbing.Value = false |
088 | grabbed.Value = false |
090 | vampchar.Head.face.Transparency = 0 |
091 | vampchar.Head.Decal.Transparency = 1 |
092 | vampchar:WaitForChild( "Humanoid:" ).PlatformStand = true |
096 | vampchar:WaitForChild( "Humanoid:" ).PlatformStand = false |
110 | local humanoidvamp = vampchar:WaitForChild( "Humanoid" ) |
111 | local hymanoid = v 2 :WaitForChild( "Humanoid" ) |
112 | local vampvalues = vampchar:WaitForChild( "charactervalues" ) |
113 | v 2. Humanoid.Died:Connect( function () |
114 | if vampvalues.Role.Value ~ = "Vampire" then return end |
115 | vampvalues.BeastMode.Value = false |
116 | vampvalues.Grabbing.Value = false |
118 | vampchar.Head.face.Transparency = 0 |
119 | vampchar.Head.Decal.Transparency = 1 |
120 | humanoidvamp.WalkSpeed = 16 |
123 | v 2. Humanoid.HealthChanged:Connect( function () |
124 | if v 2. Humanoid.Health < 10 and vampchar.charactervalues.Infect.Value = = true and v 2. charactervalues.Role.Value = = "Survivor" and v 2. charactervalues.Grabbed.Value = = true and vampchar.charactervalues.Grabbing.Value = = true then |
126 | vampchar.charactervalues.Infect.Value = false |
129 | grabbing.Value = false |
131 | grabbed.Value = false |
132 | v 2. charactervalues.Infect.Value = false |
134 | vampchar.Head.face.Transparency = 0 |
135 | vampchar.Head.Decal.Transparency = 1 |
136 | hymanoid.PlatformStand = true |
137 | v 2. charactervalues.Role.Value = "Vampire" |
138 | v 2. Humanoid.Health = v 2. Humanoid.MaxHealth |
139 | game.ServerStorage.Transformed:Clone().Parent = v 3. PlayerGui |
142 | hymanoid.PlatformStand = false |