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?
local NPC = script.Parent local Humanoid = script.Parent.Humanoid local HumanoidClone = script:WaitForChild("HClone") local Weld = script:WaitForChild("Welding") local ready = true local function Deattach(upper,lower,extremity) local hc = HumanoidClone:Clone() if upper ~= nil then local c1 = upper:Clone() c1.CanCollide = true c1.CFrame = upper.CFrame upper:remove() for i,v in pairs(c1:GetChildren()) do v:remove() end c1.Parent = hc end if lower ~= nil then local c2 = lower:Clone() c2.CanCollide = true c2.CFrame = lower.CFrame lower:remove() if upper == nil then for i,v in pairs(c2:GetChildren()) do v:remove() end end c2.Parent = hc end if extremity ~= nil then local c3 = extremity:Clone() c3.CanCollide = true c3.CFrame = extremity.CFrame extremity:remove() if lower == nil then for i,v in pairs(c3:GetChildren()) do v:remove() end end c3.Parent = hc end local wc = Weld:Clone() wc.Parent = hc wc.Disabled = false hc.Parent = workspace end Humanoid.Touched:connect(function(hit,limb) local leftupperarm = NPC:FindFirstChild("LeftUpperArm") local leftlowerarm = NPC:FindFirstChild("LeftLowerArm") local lefthand = NPC:FindFirstChild("LeftHand") local rightupperarm = NPC:FindFirstChild("RightUpperArm") local rightlowerarm = NPC:FindFirstChild("RightLowerArm") local righthand = NPC:FindFirstChild("RightHand") local leftupperleg = NPC:FindFirstChild("LeftUpperLeg") local leftlowerleg = NPC:FindFirstChild("LeftLowerLeg") local leftfoot = NPC:FindFirstChild("LeftFoot") local rightupperleg = NPC:FindFirstChild("RightUpperLeg") local rightlowerleg = NPC:FindFirstChild("RightLowerLeg") local rightfoot = NPC:FindFirstChild("RightFoot") if ready == true then ready = false if hit.Name == "Baseplate" then return end print(hit,limb) if hit.Name == "BulletTexture" then if string.sub(limb.Name,1,4) == "Left" or string.sub(limb.Name,1,5) == "Right" then if limb.Name == "LeftUpperArm" then Deattach(limb,leftlowerarm,lefthand) elseif limb.Name == "LeftLowerArm" then Deattach(nil,limb,lefthand) elseif limb.Name == "LeftHand" then Deattach(nil,nil,limb) elseif limb.Name == "RightUpperArm" then Deattach(limb,rightlowerarm,righthand) elseif limb.Name == "RightLowerArm" then Deattach(nil,limb,righthand) elseif limb.Name == "RightHand" then Deattach(nil,nil,limb) elseif limb.Name == "LeftUpperLeg" then Deattach(limb,leftlowerleg,leftfoot) elseif limb.Name == "LeftLowerLeg" then Deattach(nil,limb,leftfoot) elseif limb.Name == "LeftFoot" then Deattach(nil,nil,limb) elseif limb.Name == "RightUpperLeg" then Deattach(limb,rightlowerleg,rightfoot) elseif limb.Name == "RightLowerLeg" then Deattach(nil,limb,rightfoot) elseif limb.Name == "RightFoot" then Deattach(nil,nil,limb) end end hit:remove() end if hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(hit.Parent.Name) then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5 end end wait() ready = true end)
Closed as Too Broad by Goulstem
This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.
Why was this question closed?