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

Why won't script work correctly?

Asked by 10 years ago

I need a NPC to follow and attack a player, and have never scripted this before so I saw this on a youtube video and it doesn't work.

 Target = script.Parent.Target
Me = script.Parent.Parent
RS = script.Parent["Right Shoulder"]
Punching = false

function Chase(Part)
if Part.Parent:FindFirstChild("Humanoid") then
Target.Value = Part.Parent.Name
for chasing = 1,100 do
if Punching == false then
Me.Humanoid:MoveTo(Part.Parent.Torso.Position,Part.Parent.Torso)
end
wait(0.05)
end
end
end

function Punch (Part)
if Punching == false and Part.Parent:FindFirstChild("Humanoid") then
Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -25
v = Instance.new("BodyVelocity", Part.Parent.Torso)
game.Debris:AddItem(v,1)
Part.Parent.Humanoid.Sit = true
v.velocity = Me.Torso.CFrame.lookVector -50
v.maxForce = Vector3.new(math.huge(), math.huge(), math.huge())
Punching = true
for RSLOOP = 1,10 do
RS.C0 = RS.C0 *(CFrame.Angles(0,0,0.25)
wait(0.1) 
end
for RSLOOP = 1,10 do
RS.C0 = RS.C0 *(CFrame.Angles(0,0,-0.25)
wait(0.1) 
end
Punching = false
end
end

script.Parent.Touched:connect(Punch)
script.Parent.Touched:connect(Chase)

All it did was make the Npc wander, I was wondering what I did wrong, or if this script it self just doesn't work. I can do some simple scripting but have not been able to make an NPC follow and attack a player. Thanks

1 answer

Log in to vote
0
Answered by 10 years ago

I've tested a Walking NPC in studio. And It doesn't move anymore. I think something broke in a previous ROBLOX update?

Ad

Answer this question