[SOLVED] Why is Humanoid.Died not working on anchored characters?
Asked by
2 years ago Edited 2 years ago
When I kill an anchored character with a sword, Humanoid.Died
works. However, when I shoot it with a Hyperlaser Gun, it doesn't work.
I tried editing the tool script, I tried unanchoring, I tried SetNetworkOwner(nil)
, I tried changing the HumanoidState, I tried using Humanoid:TakeDamage()
, and I tried using Humanoid.ChildAdded
since the tool script tags the Humanoid, nothing works. I tried possible answers and solutions, still nothing works.
If you know a way, please leave your solutions and I will try them all. Thank you! ^^
Respawn Script: (the script that the Humanoid.Died event is used)
1 | local zombie = script.Parent |
2 | local hum = zombie:FindFirstChildOfClass( "Humanoid" ) |
4 | hum.Died:Connect( function () |
5 | local mrclone = game.ServerStorage:FindFirstChild(zombie.Name):Clone() |
6 | mrclone.Parent = workspace.Monsters |
7 | mrclone:SetPrimaryPartCFrame(workspace.JennaSpawn.CFrame) |
Tool Script:
004 | Handle = Tool:WaitForChild( "Handle" ) |
006 | Players = game:GetService( "Players" ) |
007 | Debris = game:GetService( "Debris" ) |
012 | NozzleOffset = Vector 3. new( 0 , 0.4 , - 1.1 ) |
015 | Fire = Handle:WaitForChild( "Fire" ), |
016 | Reload = Handle:WaitForChild( "Reload" ), |
017 | HitFade = Handle:WaitForChild( "HitFade" ) |
020 | PointLight = Handle:WaitForChild( "PointLight" ) |
022 | ServerControl = (Tool:FindFirstChild( "ServerControl" ) or Instance.new( "RemoteFunction" )) |
023 | ServerControl.Name = "ServerControl" |
024 | ServerControl.Parent = Tool |
026 | ClientControl = (Tool:FindFirstChild( "ClientControl" ) or Instance.new( "RemoteFunction" )) |
027 | ClientControl.Name = "ClientControl" |
028 | ClientControl.Parent = Tool |
030 | ServerControl.OnServerInvoke = ( function (player, Mode, Value, arg) |
031 | if player ~ = Player or Humanoid.Health = = 0 or not Tool.Enabled then |
034 | if Mode = = "Click" and Value then |
039 | function InvokeClient(Mode, Value) |
041 | ClientControl:InvokeClient(Player, Mode, Value) |
045 | function TagHumanoid(humanoid, player) |
046 | local Creator_Tag = Instance.new( "ObjectValue" ) |
047 | Creator_Tag.Name = "creator" |
048 | Creator_Tag.Value = player |
049 | Debris:AddItem(Creator_Tag, 2 ) |
050 | Creator_Tag.Parent = humanoid |
053 | function UntagHumanoid(humanoid) |
054 | for i, v in pairs (humanoid:GetChildren()) do |
055 | if v:IsA( "ObjectValue" ) and v.Name = = "creator" then |
061 | function FindCharacterAncestor(Parent) |
062 | if Parent and Parent ~ = game:GetService( "Workspace" ) then |
063 | local humanoid = Parent:FindFirstChildOfClass( "Humanoid" ) |
065 | return Parent, humanoid |
067 | return FindCharacterAncestor(Parent.Parent) |
073 | function GetTransparentsRecursive(Parent, PartsTable) |
074 | local PartsTable = (PartsTable or { } ) |
075 | for i, v in pairs (Parent:GetChildren()) do |
076 | local TransparencyExists = false |
078 | local Transparency = v [ "Transparency" ] |
080 | TransparencyExists = true |
083 | if TransparencyExists then |
084 | table.insert(PartsTable, v) |
086 | GetTransparentsRecursive(v, PartsTable) |
091 | function SelectionBoxify(Object) |
092 | local SelectionBox = Instance.new( "SelectionBox" ) |
093 | SelectionBox.Adornee = Object |
094 | SelectionBox.Color = BrickColor.new( "Toothpaste" ) |
095 | SelectionBox.Parent = Object |
099 | local function Light(Object) |
100 | local Light = PointLight:Clone() |
101 | Light.Range = (Light.Range + 2 ) |
102 | Light.Parent = Object |
105 | function FadeOutObjects(Objects, FadeIncrement) |
107 | local LastObject = nil |
108 | for i, v in pairs (Objects) do |
109 | v.Transparency = (v.Transparency + FadeIncrement) |
113 | until LastObject.Transparency > = 1 or not LastObject |
116 | function Dematerialize(character, humanoid, FirstPart) |
117 | if not character or not humanoid then |
121 | humanoid.WalkSpeed = 0 |
125 | for i, v in pairs (character:GetChildren()) do |
126 | if v:IsA( "BasePart" ) then |
128 | table.insert(Parts, v) |
129 | elseif v:IsA( "LocalScript" ) or v:IsA( "Script" ) then |
134 | local SelectionBoxes = { } |
136 | local FirstSelectionBox = SelectionBoxify(FirstPart) |
140 | for i, v in pairs (Parts) do |
141 | if v ~ = FirstPart then |
142 | table.insert(SelectionBoxes, SelectionBoxify(v)) |
147 | local ObjectsWithTransparency = GetTransparentsRecursive(character) |
148 | FadeOutObjects(ObjectsWithTransparency, 0.1 ) |
152 | character:BreakJoints() |
155 | Debris:AddItem(character, 2 ) |
157 | local FadeIncrement = 0.05 |
158 | delay( 0.2 , function () |
159 | FadeOutObjects( { FirstSelectionBox } , FadeIncrement) |
160 | if character and character.Parent then |
164 | FadeOutObjects(SelectionBoxes, FadeIncrement) |
167 | function Touched(Projectile, Hit) |
168 | if not Hit or not Hit.Parent then |
171 | local character, humanoid = FindCharacterAncestor(Hit) |
172 | if character and humanoid and character ~ = Character then |
173 | local ForceFieldExists = false |
174 | for i, v in pairs (character:GetChildren()) do |
175 | if v:IsA( "ForceField" ) then |
176 | ForceFieldExists = true |
179 | if not ForceFieldExists then |
181 | local HitFadeSound = Projectile:FindFirstChild(Sounds.HitFade.Name) |
182 | local torso = humanoid.Torso |
183 | if HitFadeSound and torso then |
184 | HitFadeSound.Parent = torso |
188 | Dematerialize(character, humanoid, Hit) |
190 | if Projectile and Projectile.Parent then |
197 | Character = Tool.Parent |
198 | Player = Players:GetPlayerFromCharacter(Character) |
199 | Humanoid = Character:FindFirstChildOfClass( "Humanoid" ) |
200 | if not Player or not Humanoid or Humanoid.Health = = 0 then |
205 | function Activated(target) |
206 | if Tool.Enabled and Humanoid.Health > 0 then |
209 | InvokeClient( "PlaySound" , Sounds.Fire) |
211 | local HandleCFrame = Handle.CFrame |
212 | local FiringPoint = HandleCFrame.p + HandleCFrame:vectorToWorldSpace(NozzleOffset) |
213 | local ShotCFrame = CFrame.new(FiringPoint, target) |
215 | local LaserShotClone = BaseShot:Clone() |
216 | LaserShotClone.CFrame = ShotCFrame + (ShotCFrame.lookVector * (BaseShot.Size.Z / 2 )) |
217 | local BodyVelocity = Instance.new( "BodyVelocity" ) |
218 | BodyVelocity.velocity = ShotCFrame.lookVector * Speed |
219 | BodyVelocity.Parent = LaserShotClone |
220 | LaserShotClone.Touched:connect( function (Hit) |
221 | if not Hit or not Hit.Parent then |
224 | Touched(LaserShotClone, Hit) |
226 | Debris:AddItem(LaserShotClone, Duration) |
227 | LaserShotClone.Parent = game:GetService( "Workspace" ) |
231 | InvokeClient( "PlaySound" , Sounds.Reload) |
243 | BaseShot = Instance.new( "Part" ) |
244 | BaseShot.Name = "Effect" |
245 | BaseShot.BrickColor = BrickColor.new( "Toothpaste" ) |
246 | BaseShot.Material = Enum.Material.Plastic |
247 | BaseShot.Shape = Enum.PartType.Block |
248 | BaseShot.TopSurface = Enum.SurfaceType.Smooth |
249 | BaseShot.BottomSurface = Enum.SurfaceType.Smooth |
250 | BaseShot.FormFactor = Enum.FormFactor.Custom |
251 | BaseShot.Size = Vector 3. new( 0.2 , 0.2 , 3 ) |
252 | BaseShot.CanCollide = false |
253 | BaseShot.Locked = true |
254 | SelectionBoxify(BaseShot) |
256 | BaseShotSound = Sounds.HitFade:Clone() |
257 | BaseShotSound.Parent = BaseShot |
259 | Tool.Equipped:connect(Equipped) |
260 | Tool.Unequipped:connect(Unequipped) |