how can i detect when a player walks out of a Humanoid:MoveTo thing?
i got a script and i created a part and when the player click on the part the player goes there with Humanoid:MoveTo and a gui is enabled but if the player walks out the gui is still visible
how can i detect when the player walk out from it and then disable the gui?
local Gifts = workspace:WaitForChild("Gifts")
for i, thing in pairs(Gifts:GetChildren()) do
thing.ClickDetector.MouseClick:Connect(function(player)
local char = player.Character or player.CharacterAdded:wait()
if (char:WaitForChild("HumanoidRootPart").Position - thing.Position).magnitude < 50 then
for _,gift in pairs(Gifts:GetChildren()) do
gift.Circle.SurfaceGui.Enabled = false
end
thing.Circle.SurfaceGui.Enabled = true
local humanoid = char:WaitForChild("Humanoid")
local RootPart = char:WaitForChild("HumanoidRootPart")
humanoid:MoveTo(thing.Position)
end
end)
end
if someone can help me out and tell me a way to do that thanks
As @1AIIHailThanos, MoveToFinished is what you need as it returns a parameter that tells you if the MoveTo was completed or it was timed out, I think what you could do is disable the GUI if it’s false? The official article for it says it’ll return false if it Timed out, so I don’t know if it would work if the player moves during the MoveTo
local Gifts = workspace:WaitForChild("Gifts")
for i, thing in pairs(Gifts:GetChildren()) do
thing.ClickDetector.MouseClick:Connect(function(player)
local char = player.Character or player.CharacterAdded:wait()
if (char:WaitForChild("HumanoidRootPart").Position - thing.Position).magnitude < 50 then
for _,gift in pairs(Gifts:GetChildren()) do
gift.Circle.SurfaceGui.Enabled = false
end
thing.Circle.SurfaceGui.Enabled = true
local humanoid = char:WaitForChild("Humanoid")
local RootPart = char:WaitForChild("HumanoidRootPart")
humanoid:MoveTo(thing.Position)
humanoid.MoveToFinished:Connect(function(completed)
if not completed then
--Disable Gui
end
end)
end
end)
end
Then I’m not sure what could be done, It’s quite odd that it doesn’t detect if it was cancelled in MoveToFinished, maybe you can try checking if the WalkToPoint was changed? MoveTo sets this to the point to move the HUmanoid to, so maybe you can use a GetPropertyChangedSignal event for the WalkToPoint of the humanoid so if changed, you can do something.
That’s…Odd I think when you move with the movement keys, it doesn’t update the WalkToPoint, I’m honestly stumped, maybe in moveto, also specify the part?
humanoid:MoveTo(thing.Position,thing)
And instead of using GetPropertyChangedSignal on WalkToPoint, use it on WalkToPart?
There has to be a way to do, but neither me or you can see it, we probably have to wait for someone to come who may have the solution. I know we can’t really detect key inputs since this isa Server Script and UserInputService only works in Localscripts
Actually we can make it work for both PC and Mobile.
For PC users, you can do it simply by checking if they’re pressing WASD and disable the GUI
For mobile, you can try to use UserInputService’s TouchMoved event so when they move their screen, remove the gui. You may have to do a few checks to see if the position where they moved is close to where they would move their player
Anytime, I wish you good luck to getting a proper, non-botched answer, if you unfortunately get nothing after a while, I hope you can somehow make my answer work almost 100%. If you have any other issues, I can try to do my best to help