Sprint not working

Hello,

I’m having problems with my sprint module, it’s very simple and it should work but it isn’t.

local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterPlayer = game:GetService("StarterPlayer")
local UserInputService = game:GetService("UserInputService")

local Source = ReplicatedStorage.Source
local Packages = ReplicatedStorage.Packages

local Settings = require(Source.Dependencies.GameSettings)
local Knit = require(Packages.Knit)

local MovementController = Knit.CreateController{
	Name = "MovementController",
}

local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid") :: Humanoid

local ACTION_SLIDE = "Slide"
local ACTION_SPRINT = "Sprint"

local function handleAction(actionName, inputState, _inputObject)
	if actionName == ACTION_SLIDE and inputState == Enum.UserInputState.Begin then
		print("Sliding")
	end
	
	if actionName == ACTION_SPRINT and inputState == Enum.UserInputState.Begin then
		if Humanoid.WalkSpeed == StarterPlayer.CharacterWalkSpeed then
			Humanoid.WalkSpeed = Settings.Sprint
		end
		
		if Humanoid.WalkSpeed ~= StarterPlayer.CharacterWalkSpeed then
			Humanoid.WalkSpeed =  StarterPlayer.CharacterWalkSpeed
		end
	end
end

function MovementController.KnitStart()
	if Character then
		bindActions(true)
	end
	
	Player.CharacterAdded:Connect(function(character: Model) 
		Character = character
	end)
end


return MovementController

Also yes, handleAction is already binded, I tested it.

This is in replicatedstorage, thats why I’m using characteradded

1 Like

In the function handleAction, you are changing the Humanoid’s WalkSpeed if its WalkSpeed is same as StarterPlayer’s CharacterWalkSpeed. After changing its WalkSpeed, then the Humanoid’s WalkSpeed is different to StarterPlayer’s CharacterWalkSpeed, so the next if - statement becomes true and it is changing Humanoid’s WalkSpeed back to its original WalkSpeed.

I suggest adding “return” after Humanoid.WalkSpeed = Settings.Sprint

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.