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

Issue with Getting NPC to follow. Error start at print(Humanoid)? Above this print works

Asked by
Hizar7 102
6 years ago
01game.Players.PlayerAdded:connect(function(Player)
02local p = game.Workspace:WaitForChild(Player.Name)
03print (p)
04local f = p.UpperTorso.Position
05print (f)
06local dist = 15
07local pos1 = f
08        for i,v in pairs(game.Workspace.CrystalMobA.UndeadWarrior:GetChildren())do
09         if v.Name == "HumanoidRootPart" then
10            print (v)
11            local z = v.Parent.Humanoid
12            local pos2 = v.Position
13            local magnitude = (pos1 - pos2).magnitude
14            if magnitude <=15 and z then
15            if p.Humanoid ~= nil then
View all 29 lines...
0
Line 2 is a bad way of getting the character, what if the characters name was "Part" OOF RIP greatneil80 2647 — 6y
0
Literally, everybody starting out to script gets their character this way. It's not wrong, but it's very inefficient. A Player object has a property called 'Charcater.' this property is your character, so to get the character, you just have to 'local p = Player.Character' oilsauce 196 — 6y
0
Also, you probably don't need the (v.Position) at line 19, local target = f(v.Position). I think it'll work if you just remove (v.Position). oilsauce 196 — 6y

Answer this question