#Npc arrests player but won't be able to move him around
1 messages · Page 1 of 1 (latest)
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