Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.