NPC script works in test mode but not the real game? [closed]
I have a script inside an NPC zombie where limbs will de-attach when shot, but it doesn't work in the actual game. I tried local script, WaitForChild variables, but nothing. No output errors are in either test mode or the real game. What's going on here?
001 | local NPC = script.Parent |
002 | local Humanoid = script.Parent.Humanoid |
003 | local HumanoidClone = script:WaitForChild( "HClone" ) |
004 | local Weld = script:WaitForChild( "Welding" ) |
007 | local function Deattach(upper,lower,extremity) |
008 | local hc = HumanoidClone:Clone() |
010 | local c 1 = upper:Clone() |
011 | c 1. CanCollide = true c 1. CFrame = upper.CFrame |
013 | for i,v in pairs (c 1 :GetChildren()) do |
019 | local c 2 = lower:Clone() |
020 | c 2. CanCollide = true c 2. CFrame = lower.CFrame |
023 | for i,v in pairs (c 2 :GetChildren()) do |
028 | if extremity ~ = nil then |
029 | local c 3 = extremity:Clone() |
030 | c 3. CanCollide = true c 3. CFrame = extremity.CFrame |
033 | for i,v in pairs (c 3 :GetChildren()) do |
038 | local wc = Weld:Clone() |
041 | hc.Parent = workspace |
044 | Humanoid.Touched:connect( function (hit,limb) |
045 | local leftupperarm = NPC:FindFirstChild( "LeftUpperArm" ) |
046 | local leftlowerarm = NPC:FindFirstChild( "LeftLowerArm" ) |
047 | local lefthand = NPC:FindFirstChild( "LeftHand" ) |
049 | local rightupperarm = NPC:FindFirstChild( "RightUpperArm" ) |
050 | local rightlowerarm = NPC:FindFirstChild( "RightLowerArm" ) |
051 | local righthand = NPC:FindFirstChild( "RightHand" ) |
053 | local leftupperleg = NPC:FindFirstChild( "LeftUpperLeg" ) |
054 | local leftlowerleg = NPC:FindFirstChild( "LeftLowerLeg" ) |
055 | local leftfoot = NPC:FindFirstChild( "LeftFoot" ) |
057 | local rightupperleg = NPC:FindFirstChild( "RightUpperLeg" ) |
058 | local rightlowerleg = NPC:FindFirstChild( "RightLowerLeg" ) |
059 | local rightfoot = NPC:FindFirstChild( "RightFoot" ) |
060 | if ready = = true then |
062 | if hit.Name = = "Baseplate" then return end |
064 | if hit.Name = = "BulletTexture" then |
065 | if string.sub(limb.Name, 1 , 4 ) = = "Left" or string.sub(limb.Name, 1 , 5 ) = = "Right" then |
066 | if limb.Name = = "LeftUpperArm" then |
067 | Deattach(limb,leftlowerarm,lefthand) |
068 | elseif limb.Name = = "LeftLowerArm" then |
069 | Deattach( nil ,limb,lefthand) |
070 | elseif limb.Name = = "LeftHand" then |
071 | Deattach( nil , nil ,limb) |
072 | elseif limb.Name = = "RightUpperArm" then |
073 | Deattach(limb,rightlowerarm,righthand) |
074 | elseif limb.Name = = "RightLowerArm" then |
075 | Deattach( nil ,limb,righthand) |
076 | elseif limb.Name = = "RightHand" then |
077 | Deattach( nil , nil ,limb) |
078 | elseif limb.Name = = "LeftUpperLeg" then |
079 | Deattach(limb,leftlowerleg,leftfoot) |
080 | elseif limb.Name = = "LeftLowerLeg" then |
081 | Deattach( nil ,limb,leftfoot) |
082 | elseif limb.Name = = "LeftFoot" then |
083 | Deattach( nil , nil ,limb) |
084 | elseif limb.Name = = "RightUpperLeg" then |
085 | Deattach(limb,rightlowerleg,rightfoot) |
086 | elseif limb.Name = = "RightLowerLeg" then |
087 | Deattach( nil ,limb,rightfoot) |
088 | elseif limb.Name = = "RightFoot" then |
089 | Deattach( nil , nil ,limb) |
094 | if hit.Parent:FindFirstChild( "Humanoid" ) and game.Players:FindFirstChild(hit.Parent.Name) then |
095 | hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5 |