How do I set up a MoveTo timeout in this situation?

NOTE: It’s been a while ever since I’ve uploaded a DevForum post, but here is one right now! Another bad situation for me.

I have been focused on making a Mario Party Based retro style game and I need to figure out how the game is going to “recover” when a player leaves. I have already scripted most of it, but during the time when the player is moving (from MoveTo) and when the player leaves, it’s a problem because it freezes.. I’d look all around the Developer Hub and the DevForum for solutions. How do I use MoveTo Timeout in this situation? (feedback on the game would also be necessary)

Code isn’t needed, but here is how I set it up:

human:MoveTo(Model.PrimaryPart.Position)
human.MoveToFinished:Wait()

I have a question, can’t you just destroy the Mario model? Or what is the problem specificly

1 Like

What mario model? I mean the idea of the game being mario party based.
Edit: The problem is, is that when the player leaves, the MoveTo code freezes. (Or so I assume)

Ooooh, ok now I see what you mean. So what you want to achieve is that the “human.MoveToFinished:Wait()” stops waiting if the player leaves

When the player leaves it actually does the opposite. It keeps waiting (sorry if I didn’t make it clear)

What you can do is that. So if you use a courutine like this: (I believe you want a timeout specificly, there is other methods which would be better)

human:MoveTo(Model.PrimaryPart.Position)

local pass = false
coroutine.wrap(function()
	wait(10)
	pass = true
end);
coroutine.wrap(function() human.MoveToFinished:Wait(); pass = true end)

repeat wait() until(pass == true);
1 Like

There is a better method, and it is that when the player leaves the humanoid disappears, so you can also do this

local pass = false;
coroutine.wrap(function() human.MoveToFinished:Wait(); pass = true end)();
repeat wait() until(pass == true or not human);

Okay wait I am testing it… so I have to make a custom time when it stops?

Well, if by custom time you mean the amount you want the timeout to be, yes. For the other method you dont need timeout

It looks like it just freezes my character not even on leave.
Edit: No errors in output.

What do you mean “not even on leave”? Also try to add a print after, to see if it prints exactly after you leave, because if that is the case then it is working

So it moves to the location (which is good) but I want it to move to another space, which it’s not even moving. I haven’t tested if it breaks when the player leaves.

Also to answer your second question, it doesn’t print.

Wait, I didn’t understand, did you test if it runs when you leave? Because when you leave is when the print should print, I am asking this because of what you said" I haven’t tested if it breaks when the player leaves."

Another question is, you want the character to remain? Because if the character is the normal player character, when the player leaves it gets destroyed. Also, where are you executing this script, because if it is in a local script it won’t print, since when the player leaves the local scripts also get destroyed

I was initially going to test if it runs when I leave, but instead I found out that it freezes after it moves to the space.

No, instead I just want the MoveToFinished to break when the player leaves. When the player leaves, nothing happens and nothing is in the output.

I am currently executing this script on a ServerScript.

OHHH, Now I see. So sorry my silly mistake. I forgot the “()”. Wrap returns a function, it needs to be called.

1 Like

It’s fine! :sweat_smile: all of us make mistakes once in a while. I tested it if it glitches when it moves and it works! I also tested if the player left, and the print does work.

Edit: Please edit the solution because players will get confused.

1 Like