I want to make the WalkToPoint and MoveToFinished event without a humanoid but the problem I am having is that I don’t know how it works with Roblox’s code.
local module = {}
local RunService = game:GetService("RunService")
local connections = {
["WalkToPoint"] = nil
}
local character = script.Parent.Parent
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
local MoveVelocity = script.Parent:WaitForChild("MoveVelocity")
local AlignOrientation = script.Parent:WaitForChild("AlignOrientation")
local StandVelocity = script.Parent:WaitForChild("StandVelocity")
function module.UpdateAlignOrientation()
local velocity = MoveVelocity.PlaneVelocity
local direction
if velocity.Magnitude <= 0 then
direction = HumanoidRootPart.CFrame.LookVector * Vector3.new(1, 0, 1)
else
direction = Vector3.new(velocity.Unit.X, 0, velocity.Unit.Y)
end
local newOrientation = CFrame.new(Vector3.new(), direction)
AlignOrientation.CFrame = newOrientation
end
function module.WalkToPoint(position)
if connections["WalkToPoint"] then
connections["WalkToPoint"]:Disconnect()
connections["WalkToPoint"] = nil
end
coroutine.wrap(function()
connections["WalkToPoint"] = RunService.Heartbeat:Connect(function()
local distance = (HumanoidRootPart.Position - position).Magnitude
if distance <= 3 then
module.MoveToFinished()
else
local WalkSpeed = character:GetAttribute("WalkSpeed")
local direction = (position - HumanoidRootPart.Position).Unit
local direction2D = Vector2.new(direction.X, direction.Z)
MoveVelocity.PlaneVelocity = direction2D * WalkSpeed
end
end)
end)()
end
function module.MoveToFinished()
MoveVelocity.PlaneVelocity = Vector2.new()
print("move to finished")
character:SetAttribute("MoveToFinished", true)
RunService.Heartbeat:Wait()
character:SetAttribute("MoveToFinished", false)
if connections["WalkToPoint"] then
connections["WalkToPoint"]:Disconnect()
connections["WalkToPoint"] = nil
end
end
return module