#Npc arrests player but won't be able to move him around

1 messages · Page 1 of 1 (latest)

rain moss
#

I have this Npc class that follows player around with the purpose of arresting them; the npcs can successfully reach the players, but once they do they won't be able to move them around to "bring them home"

#

CODE:

function Npc:bringPlayerHome(player: Player)
    
    local instance = self.Instances[player]
    if not instance then return end
    
    -- Stopping the chase on the player's client
    instance.PrimaryPart:SetNetworkOwner(nil)
    Events.ToClient.StopNpcChase:FireClient(player, instance)
    
    -- Aligning the player in front of the npc
    local playerCharacter = player.Character
    playerCharacter:PivotTo(instance:GetPivot():ToWorldSpace(CFrame.new(0, 0, -2)))
    
    -- Welding the player to the npc (like an arrest)
    local weld = Instance.new("WeldConstraint")
    weld.Part0 = instance.PrimaryPart
    weld.Part1 = playerCharacter.PrimaryPart
    weld.Parent = instance
    
    -- Moving the npc to the home position
    repeat
        instance.Humanoid:MoveTo(self.HomePosition.Position)
        task.wait(0.5)
    until (instance:GetPivot().Position - self.HomePosition.Position).Magnitude < 1
    
end