Weird behavior with NPCs when following player, but not when following eachother

Hello, so, I’m making a turn based combat game, and in the overworld you’ll have followers which trail behind the party leader, like in mother 3 if you’ve played it. Now the scripts I have prepared for this work fine, however, there’s a visual issue that has been grinding at me for a while and I’m not really sure how to fix the problem. Follower #2 seems to delay following the party leader while follower #3 and onward have no issues of following the NPC infront of them, I think it has to do with the way the server responds or something because it only happens with NPCs following the player and not other NPCs. Also NPCs behind the player have a script in them that sets their network client ownership to NIL, so they don’t glitch-walk forwards when moving, and I’m 90% sure that may having something to do with it.

You can see in this video, the second follower takes a while to start following the player, while the third moves as soon as #2 moves, which makes the follower in the second slot trail way farther behind the party leader than it should be.

Sorry if my code is trash, this is the first time I’ve tried making something on my own.
Here’s like, the main follower code:

local ValuesFolder = script.Parent.Parent.Values -- this is just a big folder in the NPC which shows if they should be following somebody and who they should be following.
repeat wait() until ValuesFolder.WhoToFollow.Value ~= nil and ValuesFolder.SlotNumb.Value ~= 0 or nil -- waits until they're told to start following to function

local function Follow()    
    local SlotNumber = ValuesFolder.SlotNumb.Value -- which slot a character is in, 1 would be the playable character, and 2+ is an NPC follower.
    local IsFollowing = ValuesFolder.IsFollowing.Value -- a bool. When true, follow the character infront.
    local WhoToFollow = ValuesFolder.WhoToFollow.Value -- an object value of who they should be following if the slot is 2+. 
    local PartyMember = script.Parent.Parent
    if ValuesFolder.IsFollowing.Value == true and WhoToFollow ~= nil then
        local PartyMemberToFollowPosition = WhoToFollow.HumanoidRootPart.CFrame
        local TargetPosition = PartyMemberToFollowPosition * CFrame.new((PartyMember.HumanoidRootPart.Position).Unit * 0,0,5) -- slight distance between characters.
        PartyMember.Humanoid:MoveTo(TargetPosition.Position)
                
        local DistanceFromPartyMemberToFollow = ((PartyMember.HumanoidRootPart.Position - TargetPosition.Position).magnitude)
        if DistanceFromPartyMemberToFollow > 16.5 then -- only move if the distance is greater than that.
            PartyMember.HumanoidRootPart.CFrame = TargetPosition            
        end    
    end    
end

while true do -- I'm 90% sure this is a bad practice but I don't believe it's the issue, but if you have a better way of doing this I'd like to hear it anyways.
    wait()
    Follow()
end

Here’s the code for the network ownership script just incase:

local NPCparts = script.Parent.Parent:GetChildren()
wait()
for _, Item in ipairs(NPCparts) do
	if Item:IsA("BasePart") or Item:IsA("UnionOperation") then 
		Item:SetNetworkOwner(nil)
	end
end

Hopefully this post was able to clarify my issue, I haven’t made a post before so I’m sorry if I make any screw ups in the post itself.

2 Likes

My best guess is that this is due to latency between the server and the player. It may just be better to allow the player to directly change the CFrame of the followers instead of the server (by setting NetworkOwner to the player, they are allowed to change CFrame whenever they like without needing to tell the server).

1 Like

eeee! Thank you! I’m really unfamiliar with network client junk so thanks for the tip about setting it to the player. Because of the change, I now have to adjust some animation scripts as well so they don’t lag behind, do you think it would be a decent idea to keep local animation scripts inside the StarterPlayerScripts (in a designated folder) for follower NPCs so their animations don’t lag behind?

What do you mean “adjust some animation scripts as well so they don’t lag behind”? You can play animations from the player and they will replicate to the server, correct? I’m not sure if the player specifically can play animations for other models (followers), but you could try that since I know that the server should pretty much never be the one animating anything.

From the Roblox wiki: “A Model is considered locally controlled if it has network ownership of the model, clients have network ownership of the local character model by default and other models can be assigned to a different client using BasePart:SetNetworkOwner

I’m a clown and typically I played the normal walk/idle animations in server scripts which were children of the follower, when I set their network owner to the player the animation script wouldn’t actually be in sync with their movement anymore and it would take a little bit longer to play whatever animation was needed, and take a bit longer to stop it too. I read on another page that you can have local animation scripts for other NPCs inside of the player scripts (as long as you define the NPC in the local script), and it seemed to work cuz it synced up with my followers. Does it seem like a good practice to do it that way? Sorry, I’m pretty bad at wording questions

It seems good. Just don’t have the server do any animating is all. Have the player be responsible for animating their character and any other characters in their posession.

1 Like

Alright, yet again, thank you so much for helping, this issue was bugging me a lot.