Customer speeds out the store but the WalkSpeed never changes

The Customers WalkSpeed is 12.

This is what it looks like when they enter the store:

For some odd reason though, when they leave they’re speed out the store but the WalkSpeed remains the same (12).
When the Customer is walking out:

I can’t figure out the reason behind this.

function Customer.Move(Humanoid, Position)
    Humanoid:MoveTo(Position)
    Humanoid.MoveToFinished:Wait()
end

function Customer.Leave(Character)
    local Customers = Character.Parent
    Character.Parent = workspace
    spawn(function()
        for _, Character in pairs(Customers:GetChildren()) do
            Customer.MoveInQueue(Character)
        end
    end)
    local Humanoid = Character.Humanoid
    Customer.Move(Humanoid, Middle)
    Customer.Move(Humanoid, Entrance)
    Character:Destroy()
end

The spawn(function()) isn’t relevant. The code below it is what moves the leaving Customer.
If anyone has an idea why this is happening, do telll.

Can I see the Customer.MoveInQueue function? and Customer.Move.

I’ve already included the Customer.Move function. I’m not adding my Customer.MoveInQueue function as it’s irrelevant to the code. The Customer that is leaving is no longer inside the Customers folder so the function is irrelevant.

It would help if we could see this function too.

Why? As I said before, it’s irrelevant to the problem as the Customer that is leaving is not a child of the Customers folder, so the MoveInQueue function doesn’t affect them.

The code that you show here looks fine. How does the code where the customer enters looks like?

It looks fine, and acts fine. I don’t need to post every function in my Customer Module as it’s not needed.

Of course you don’t need to post the entire customer module, but the point @Redridge and others are trying to make is that, while the code you have posted seems like it should work fine, code from .MoveToQueue() may be somehow affecting the character walking away from the queue, even if you don’t think it is.

If you’re not comfortable sharing the rest of the code, that’s okay too, but just remember people are actually trying to help you :stuck_out_tongue:

I can’t see anything immediately wrong with your code, and since the WalkSpeed isn’t changing the issue could involve multiple MoveTo’s being called, or something like that? Have you tried using the Debugger? Perhaps you could step through the code to determine where the problem begins. Good luck :slight_smile:

function Customer.MoveInQueue(Character)
	local Queue = Character.Parent.Parent
	local ServePosition = Queue.Serve.Position
	local PositionInQueue = Customer.GetQueuePosition(Character, Queue)
	
	local ZPosition = ServePosition.Z + (Gap * PositionInQueue)
	Customer.Move(Character.Humanoid, Vector3.new(ServePosition.X, Character.HumanoidRootPart.Position.Y, ZPosition))
	
	if PositionInQueue == 0 then
		Character["Order UI"].Bubble:TweenSize(UDim2.new(.83, 0, 1, 0), "InOut", "Linear", .15, false)
		CollectionService:AddTag(Character, "CanServe")
	end
end

This is the MoveInQueue function. It only runs for the Customers in the Customers folder (which the Leaving Customer) is not a child of which is why I am reluctant to post it.

This line could cause the problem.

I am not sure how lua scope works but maybe change the variable name from Character to _Character in the for loop. It could be the case that you are passing the original “Character” as argument to MoveInQueue.

Otherwise what you could do is debug with prints. Print the name of the character and see if he is added to the queue wrongly.

I tried _Character instead but it didn’t fix anything.
I don’t think printing would help, as the code isn’t broke and the walkspeed doesn’t change at all. So I don’t know how I’ll figure out the problem.

Make sure the changed loop looks like this

for _, _Character in pairs(Customers:GetChildren()) do
    Customer.MoveInQueue(_Character)
end

By printing I mean print the Character.Name in Leave and the Character.Name in MoveInQueue. There should never be a match.

My code is exactly the same as yours. I’ve also tested with prints and there’s no match. If I remove the spawn(function() and the inner code all together - the problem still exists so it’s got nothing to do with that.

One last idea. Try and set his walkspeed to 1 (or something low) before he leaves. See if he still speeds out like that.

Alright lets start with this, if you set the walkspeed even slower, to something like 7 or even 5, does the speed at which the humanoid leaves slow down at all?

if not, there’s probably something else controlling the character instead. Do you have 2 humanoids somehow?

If I lower the WalkSpeed, the speed that the Customer leaves is slower.

There’s only one Humanoid in the Customer Dummy.

cc @Redridge

This is a pretty interesting scenario to bring up actually. I noticed that there are brief instances of inconsistent speed while the customer enters the store as well, while their exit speeds them up by a great amount. I couldn’t quite figure anything out with the code given at this time.

For clarification’s sake and the possibility of creating a repro: the only time you move humanoids around is via the MoveTo function in Humanoids and to spawn in customers, right? If not, are there any other instances in which you explicitly move around NPCs?

I am running the code below and it seems to work fine. The way it looks from the limited code you gave seems to maybe be caused by the customer spawn(function() try commenting it out and try it. the reason I say this is because it seems to be getting the same customer you are running the function for declared in the variable Character when it gets children from the Character’s parent… then it runs Customer.MoveInQueue(Character) which is in turn using the same variable as your main function (Character) and also including that current Character/Customer…

local Customer = {}
local Middle = workspace.Middle.Position
local Entrance = workspace.Entrance.Position

function Customer.Move(Humanoid, Position)
    Humanoid:MoveTo(Position)
    Humanoid.MoveToFinished:Wait()
end

function Customer.Leave(Character)
   -- local Customers = Character.Parent
    Character.Parent = workspace
   -- spawn(function()
  --      for _, Character in pairs(Customers:GetChildren()) do
    --        Customer.MoveInQueue(Character)
  --      end
  --  end)
    local Humanoid = Character.Humanoid
    Customer.Move(Humanoid, Middle)
    Customer.Move(Humanoid, Entrance)
    --Character:Destroy()
end

return Customer

I already removed the spawn function and the relevant code, problem still persists.

you run that exact code above and still the same?
what code are you running now?

and how is it being called?