How do I change players walk speed on low health

So, my goal is to have an effect when a players health gets low, there walk speed in decreased.
I got the blur effect and the sounds to work, now I just need to figure out how to make the effect of slow walking when the players health is low. I don’t know where to start really, I am learning how to script and don’t know the functions of Lua all to well. Anything will help,

Thanks!

1 Like

Place a .Changed on the health of the player to fire changes to the walkspeed. And set the walkspeed to 6 + (health/10) such that at full health the player has the base walkspeed of 16 and as the health decreases the walkspeed decreases until 6 upon which the player dies.

1 Like

How would that look on a script? Also would this be in startercharacterscripts or in player?

https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged
https://developer.roblox.com/en-us/api-reference/property/Humanoid/WalkSpeed

1 Like

local maxSpeed = 16 – normal walkspeed or is it the lower walkspeed i want?
local currentHealth = 30 – low health

local newSpeed = maxSpeed * (currentHealth /16)

local maxSpeed = 16
local maxHealth = 100
local currentHealth = 30

local newSpeed = maxSpeed * (currentHealth /maxHealth )

yup smth like that. You decide on the formula tho.

1 Like

yo wait i think i got it!

local Humanoid = script.Parent:WaitForChild(Humanoid)

local LowSpeed = 5

local NormalSpeed = 30

while wait() do

if Humanoid.Health < 30 or Humanoid.Health == 30 then

Humanoid.WalkSpeed = LowSpeed

else
Humanoid.WalkSpeed = NormalSpeed

end
end

Ay thanks for the help!

pretty neat, you set the speed of the player based on a predefined WalkSpeed value then divide that WalkSpeed value by the MaxHealth of the Humanoid and then that MaxHealth by the Humanoid’s Health

like

Humanoid.WalkSpeed = (16/(Humanoid.MaxHealth/Humanoid.Health))

The lower the player’s health is, the slower they will be, otherwise their walkspeed will be 16


in the video I clamped the speed to a minimum of 1 WalkSpeed just incase

3 Likes

Thanks looks awesome appreciate the extra effort for the help! :smiley: