Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The Humanoid Wont Move?

Asked by 3 years ago
Edited 3 years ago

So I'm trying to make a character that scans for the closest marker and then moves to it but I don't know why it isn't working.

game:WaitForChild("Workspace")

local markers = game.Workspace.Markers:GetChildren()
local hum = script.Parent.Humanoid
local humRoot = script.Parent.HumanoidRootPart


local function findClosestMarker()
    local currentMarker = nil
    local shortestMarker = math.huge
    local chosenMarker = nil

    for i, marker in pairs(markers) do
        local distance = (marker.Position - humRoot.Position).magnitude
        currentMarker = distance
        if currentMarker <= shortestMarker then
            shortestMarker = currentMarker
            chosenMarker = marker
            print("Found Closer Marker")

        elseif currentMarker > shortestMarker then
            print("Did Not Find Closer Marker")
        end
    end
    return chosenMarker
end

hum:MoveTo(findClosestMarker().Position)
hum.MoveToFinished:Wait()

1 answer

Log in to vote
0
Answered by 3 years ago

So it turns out I'm actually just stupid and spent 10 hours total trying to figure this out. part of the character was anchored

Ad

Answer this question