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