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

Ai following one player please help?

Asked by 6 years ago

I´m creating a horror game, i created a mian script who works for all ai on a folder but i have a problem it follows only one player and ignore the others players

001local Distance = 40
002 
003local Damage = 100 
004 
005local scaryimg = game.ReplicatedStorage:WaitForChild("ScaryPlayer")
006 
007local candamage = true
008 
009local Wander = true
010local WanderX, WanderZ = 10, 10
011 
012function Added(Monsters)
013    spawn(function()
014 
015    function getHumanoid(model)
View all 172 lines...

Help me please i need this urgently Thanks

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You issue is likely here:

01function GetTorso(part)
02            local chars = game.Workspace:GetChildren()
03            local torso = nil
04            for _, v in pairs(chars) do
05                if v:IsA'Model' and v ~= script.Parent and v.Name == GetPlayerNames() then
06                    local charRoot = v:FindFirstChild'HumanoidRootPart'
07                    if (charRoot.Position - part).magnitude < Distance then
08                        torso = charRoot
09                    end
10                end
11            end
12            return torso
13        end

Specifically here:

1local charRoot = v:FindFirstChild'HumanoidRootPart'
2              if (charRoot.Position - part).magnitude < Distance then
3                  torso = charRoot
4              end

You are not comparing the player distances, you will always get the last player in the Chars table. Assuming you are going for the closest player, you need to compare the current v value with the current torso's distance to the monster and set torso equal to which one is closer.

0
ok thanks imagYTOP 19 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

i Tried make something similar like you said me but i don´t works:

01--New Code
02 
03function GetTorso(pos)
04        local char = game.Workspace:children()
05        local torso = nil
06        local Id = nil
07        local human = nil
08        local Ad = nil
09        for ea = 1, #char do
10            Ad = char[ea]
11            if (Ad.className == "Model") and (Ad ~= script.Parent)  then
12                Id = Ad:findFirstChild("Torso")
13                local charRoot = Ad:findFirstChild("Humanoid")
14                if (Id ~= nil) and (charRoot ~= nilthen
15                    if (Id.Position - pos).magnitude < SearchDistance then
View all 22 lines...

please help me with this thanks

sorry im so noob with the pathfinder

Answer this question