Preventing Player from Sprinting Backwards

Hello!

What I need help with:
I need help preventing players from sprinting while walking any other direction then forwards. I have tried numerous things without luck and could use a little help.

Does anyone have any suggestions on what to use to detect this?

I reccomend removing the character’s legs.

You can do this with

Character.LeftLeg:Destroy()
Character.RightLeg:Destroy().


@VegetationBush has just informed me this may not work. Alternatively you could just remove the head with

Character.Head:Destroy().

This would also prevent the character from walking

You could also add a sign to the game asking the player to not sprint backwards.

You would do this by inserting a part, the inserting a surface gui, then inserting a text label

don’t forget to check if he is holding the down arrow!

As a consideration you should also check if they are on mobile. Then if they are you can just kick them from the game

Maybe disabling walking backwards would help. You would need to write a custom movement script that respects textboxes though.

Im just crying from these posts. :rofl:

Anyways, you can check Humanoid.MoveDirection.Z. If its -1, then the player is moving forward.

While this would work I feel it is incredibly inefficient since you would have to like regularly check the move direction whereas with the above solutions it’s really just running once.

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
   if Humanoid.MoveDirection.Z == -1 then StopSprint() end
end)

Even if you would make your own movement script, you would need to do the same.

Check if they are holding “W” + “SHIFT”

local UserInputService = game:GetService("UserInputService")

local HoldingW = false
local HoldingShift = false

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		HoldingW = true
	elseif input.KeyCode == Enum.KeyCode.LeftShift then
		HoldingShift = true
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		HoldingW = false
	elseif input.KeyCode == Enum.KeyCode.LeftShift then
		HoldingShift = false
	end
end)

if HoldingW == true and HoldingShift == true then
	print("RUN")
end

Guessing you have button for sprint just add the Ole “and” and check of they are also pressing the forward button.

@Dr_Bloomfield @cornholio11111

  1. It will only work for pc
  2. It is possible to walk backwards, while holding shift and w.

Very helpful to the topic, thanks for posting this incredibly informative reply.