Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gun-using NPC won't stop shooting after it died?

Asked by 4 years ago
Edited 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

I have a certain NPC in my game that uses a gun, and when you kill it it keeps on shooting! Here is the script for the NPC, everything is in here


wait(.1) local ammo=29 local w=.14 local r=false local t=script.Parent Spawn(function() local c=t:Clone() wait(1) t.Humanoid.Died:wait() wait(45) c.Parent=workspace c:MakeJoints() t:Destroy() end) local cf={CFrame.new(.8,.5,.4)CFrame.Angles(math.rad(270),math.rad(40),0),CFrame.new(-1.2,0.5,0.4)CFrame.Angles(math.rad(270),math.rad(-5),0)} local c= require(game.ReplicatedStorage:WaitForChild("LoadLibrary"):WaitForChild("RbxUtility") ).Create local b1=c'Part'{TopSurface=0;BottomSurface=0;Anchored=true;CanCollide=false;BrickColor=BrickColor.new("Cool yellow");Size=Vector3.new(.2,.2,1);c'SpecialMesh'{MeshType=6;Scale=Vector3.new(.2,.2,1)}};Transparency=.5 local b2=b1:Clone() b1.Name,b2.Name='1','2' local mov=c'Part'{Transparency=1;CanCollide=false;Parent=t;Anchored=true} local h=t:WaitForChild'Handle' local function reload(boo) if(boo and ammo~=30)or ammo==0 then r=true if w then w=.03 end h.Reload:Play() wait(3) ammo=30 if w then w=.14 end r=false elseif boo then wait(.1) end end local function near() local dis,pl=300,nil for ,v in ipairs(game.Players:GetPlayers())do if v.Character and v.Character:FindFirstChild'Humanoid'and v:DistanceFromCharacter(h.Position)<dis then dis,pl=v:DistanceFromCharacter(h.Position),v end end if pl then return pl.Character:GetModelCFrame(),dis,CFrame.new(pl.Character.Humanoid.WalkToPoint).lookVector else return nil end end Spawn(function() while true do t.Humanoid.Jump=false while not w do wait(.1)end for i=1,math.random(4,9)do wait(w) end end end) Spawn(function() while wait(math.random(2,7)/10)do local n=near() if n and math.random(1,3)==2 or not n then mov.CFrame=t.Torso.CFrame+t.Torso.CFrame.lookVectorVector3.new(math.random(-25,25),0,math.random(-25,25)) else mov.CFrame=n+Vector3.new((math.random(1,2)==1 and 1 or -1)math.random(25,50),0,(math.random(1,2)==1 and 1 or -1)*math.random(25,50)) end wait(.1) t.Humanoid:MoveTo(mov.Position,mov) end end) while true do local n,mag,hum=near() if n then n=n.p if not r then w=.14 local dir=h.Position-n local tst,=workspace:FindPartOnRay(Ray.new(t.Torso.Position,(n-t.Torso.Position).Unit999),t) local aim=n+Vector3.new(math.random(-mag.015,mag.015),math.random(-mag.015,mag.015),math.random(-mag.015,mag.015))(2+math.random())+hum if tst and tst.Parent and game.Players:GetPlayerFromCharacter(tst.Parent)then wait(.08) h.Fire:Play() local par,pos=workspace:FindPartOnRay(Ray.new(h.Position,(aim-h.Position).Unit999),t) if par then local h=par.Parent:FindFirstChild'Humanoid'or par.Parent.Parent:FindFirstChild'Humanoid' if h and h.Health-10>0 then h.Health=h.Health-4 elseif h then h.Health=0 h.Parent:BreakJoints() end end ammo=ammo-1 mag=(h.Position-pos).magnitude b1.Parent,b2.Parent=t,t b1.CFrame,b2.CFrame=CFrame.new(h.Position:Lerp(pos,.375),pos),CFrame.new(pos:Lerp(h.Position,.125),h.Position) b1.Mesh.Scale,b2.Mesh.Scale=Vector3.new(.2,.2,mag.75),Vector3.new(.2,.2,mag/4) Delay(.03,function()b1.Parent=nil wait(.03)b2.Parent=nil end) end wait(.05) if ammo==0 then reload() end end else reload(true) w=false end end

0
Can you put that into a code block by pressing the "Lua" button? It's very hard to read. youtubemasterWOW 2741 — 4y
0
please User#23252 26 — 4y
0
Please use the Lua Code Blocks button, this is very difficult to read. killerbrenden 1537 — 4y
0
For some reason most of the script is in italics and bunched up, and I do not know how to fix that problem super_guy157 0 — 4y

Answer this question