To sum up the code below I’m trying to make a “killer NPC” he walks between two points called ‘Start’ and ‘End’. On his way from End to start if you are within a distance of 15 or less it kills you. I’m fairly new to coroutines. v is a model called ‘Walking Person’, which holds start, end, and the NPC. It works until the character dies then he stops moving. Also this is server side so the item with ‘WalkingPerson’ in it is being cloned. And when there are 2 players or more in a server, it gets messed up, nothing moves. Hopefully, its just a way I wrote the coroutines. If you could give a hand that would be amazing, if not no worries!
Also, I know this isn’t complete code but the values being passed are true so I’m sure the mess up is coming from the coroutine.
local walkingPerson = coroutine.create(function(v, player) while true do wait() v:WaitForChild("NPC").Humanoid:MoveTo(v.End.Position) v:WaitForChild("NPC").Humanoid.MoveToFinished:wait() local targetReached = false v:WaitForChild("NPC").Humanoid:MoveTo(v.Start.Position) v:WaitForChild("NPC").Humanoid.MoveToFinished:Connect(function(successful) targetReached = true end) while not targetReached do local character = player.Character or player.CharacterAdded:wait() if player:DistanceFromCharacter(v:WaitForChild("NPC").HumanoidRootPart.Position) <= 15 then character:WaitForChild("UpperTorso"):Destroy() end wait() end end end) if v.Name == "WalkingPerson" then coroutine.resume(walkingPerson, v, player) end