My character runs in Place

Here’s how I’d do it.

local UserInputService = game:GetService("UserInputService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("Humanoid")

local sprinting = false

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then
		return
	end
	
	if (input.KeyCode == Enum.KeyCode.LeftShift and (UserInputService:IsKeyDown(Enum.KeyCode.W)) and not sprinting then
		sprinting = true
		print("Start running!")
		
		local running = nil
		running = character.Humanoid.Running:Connect(function(speed)
			if speed < 1 then
				print("Stop running!")
				sprinting = false
				running:Disconnect()
			end
		end)
	end
	
end)

Checking every frame just for a simple sprint script is horribly inefficient, you should always look for other methods before you use a loop.

This may be considered inefficient to some people, but if you’re using a localscript you can use Humanoid.MoveDirection to determine whether the player’s moving or not.

For instance:

local Hum = Character:WaitForChild("Humanoid")
game:GetService("RunService").RenderStepped:Connect(function()
if Hum.MoveDirection == Vector3.new(0,0,0) then
-- not moving
else
-- moving
end
end)

While it is extremely inefficient, it actually causes no issues at all, especially since it is on the client.

Also, your method relies on mostly on UIS, which also makes inefficient. W is a game-processed event. (not sure about this one)

I fail to see your point on how my code is “inefficient”, when it’s leagues more efficient than creating event connections every single frame, which would cause a memory leak.You should generally use RenderStepped for creating camera systems. I used IsKeyDown as it’s a very simple method.

Would you also mind linking a source as to ‘W’ being a game processed event?

I’m not sure what you mean by inefficient but creating a new connection under renderstepped event is much more of an issue. Please take a look at memory leaks and don’t go calling methods and functions “inefficient” without any explanations why.

This does not need to run every RenderStepped. Why are you looping when you’re listening to events? I have so many questions and so many things I could add, but this is BEYOND inefficient to the point of real harm.

Connecting the same event again and again (in RS) seems quite dangerous, much more inefficient than xKai’s one (not saying xKai’s one is inefficient).

Oh, anyway, if you think UIS is inefficient, what are you going to use for user input? GuiObject.InputBegan? CAS?

Your comment is quite harsh, by the way, have you researched on what you were saying?

Apparently I mixed Dracolyx with your code, I meant to reply to his which it included MoveDirection and RenderStepped when I found out about yours, turns out I actually replied to the wrong person and the wrong code since I was half-awake at this time, my bad