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

Can someone tell me why this if statement for humanoid:MoveTo() doesnt work?

Asked by 4 years ago
Edited 4 years ago

So im working on a move player character script but am confused with why is this if statement not working:

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local playerModule = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
local control = playerModule:GetControls()
local human = player.Character:WaitForChild("Humanoid")
control:Disable()




    local function moveTo(humanoid, targetPoint)
        local targetReached = false

    connection = humanoid.MoveToFinished:Connect(function(reached)
        targetReached = true
        connection:Disconnect()
        connection = nil
    end)

        -- start walking
        humanoid:MoveTo(targetPoint.Position)

        spawn(function()
            while not targetReached do
                -- has the target changed?
                if humanoid.WalkToPoint ~= targetPoint.Position then --THIS DOESNT WORK
                    break
                end
                -- refresh the timeout
                humanoid:MoveTo(targetPoint.Position)
                wait(6)
            end

            if connection then
                connection:Disconnect()
                connection = nil
            end
        end)
    end

mouse.Button1Down:Connect(function()
local point = Instance.new("Part", game.Workspace)
point.Position = mouse.Hit.Position
moveTo(human, point)    
end)

as you can see, line 27 doesnt work, it automatically breaks the spawn function so the character would abruptly stop instead of going to the end, but i cant seem to find the problem. this is the whole script.

1 answer

Log in to vote
1
Answered by 4 years ago

Fixed it, the targetpoint wasn't anchored -_-

Ad

Answer this question