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.
