#Trying to change humanoid walk speed based onHumanoidStateType

2 messages · Page 1 of 1 (latest)

formal spire
#

Your code has nothing to detect a change in the Humanoid's state to tell it to run the code, so what is happening is your code is running once on startup and then never running again.
We can add the event Humanoid.StateChanged to tell the code to run each time the Humanoid changes states.

Conveniently, this event also tracks two arguments: the previous state and the new state. This removes the need to call :GetState() since we already know what the new state is.

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
humanoid.StateChanged:Connect(function(OldState, NewState)
  if NewState == Enum.HumanoidStateType.Freefall then
      humanoid.WalkSpeed = 100 -- it is made like this on purpose so i could tell if it works at all or not
      print(humanoid.WalkSpeed)
  end
end)