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)
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)
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.
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