How can I make the walkspeed slower if I walk backwards or left or right

Heres my attempt it works but it also no longer lets the walk keys work.

local player = game:GetService("Players").LocalPlayer
local character = player.Character

local function SlowWalk()
	print("InitializeSlowWalk")
	character.Humanoid.WalkSpeed = 0
end

local function NormalWalk()
	print("InitializeNormalWalk")
	character.Humanoid.WalkSpeed = 16
end

contextActionService:BindAction("SlowWalkSpeed", SlowWalk, false, "s")

contextActionService:BindAction("NormalWalkSpeed", NormalWalk, false, "w")

you can use humanoid.MoveDirection to determine how the character is moving to know if they are going left/right

1 Like

You’re binding the action, therefore, you’re overwriting the purpose of S and W, which are allowing the player to walk in their respective direction. Instead, use UserInputService.InputBegan:

game:GetService("UserInputService").InputBegan:Connect(function(input)
    local key = input.KeyCode
    if key == Enum.KeyCode.W then
        NormalWalk()
    elseif key == Enum.KeyCode.S then
        SlowWalk()
    end
end)
2 Likes

how can I call a function from earlier in the script?

I know how to connect a new function

	if key == move_Forward and not gameProccessedEvent then
		print("W")
		character.Humanoid.WalkSpeed = 12
	elseif key == move_Backward and not gameProccessedEvent then
		print("S")
		character.Humanoid.WalkSpeed = 6
	end
end

userInputService.InputBegan:Connect(walk_())

but I want to call walk_() but I dont know the correct syntax.

Simply remove the brackets inside the parameter (walk()), as you’re already calling it in an event.

1 Like