How to scale players HUD when going a certain speed?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a script that scales the players HUD when going a certain speed.

  2. What is the issue? Include screenshots / videos if possible!

    Can’t figure it out, I’m pretty sure my script I made is fine, but it just doesn’t work?

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Here is the script I made that didn’t work :

local topspeed = 20

local HUD = script.Parent

local character = game.Players.LocalPlayer.Character

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

character.Humanoid.Running:Connect(function(speed)

if speed >= topspeed then

HUD:TweenSize(UDim2.new(0, 400, 0, 100))

end

end)

If anyone could help, that would be awesome! Thanks!

1 Like

Just to be clear, the new UDIM2 size is DEFINITELY larger than the original size?

yes i know, to be honest, it was just for testing purposes, i just put it random values to see if it worked.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 25
local HUD = script.Parent

local topspeed = 20

humanoid.Running:Connect(function(speed)
	if speed >= topspeed then
		HUD:TweenSize(UDim2.new(0, 400, 0, 400))
	end
end)

This is working for me, remember that the WalkSpeed property is by default assigned a value of 16, in the script I’ve changed this to 25 so that the conditional statement evaluates to true.

https://gyazo.com/ab1e651796674d9babfef18dc3ad3cd1

The script is a local script placed inside a frame.

What I also recommend is not defying anything but the player here, and doing player.Character.Humanoid.Running because that would work even if the player resets.
The character saved in a variable won’t be the same if you reset

The script executes each time the Gui is copied from the StarterGui folder into the PlayerGui folder anyway, and it’s safer to add waits like this.

Instead of using walk speed and Humanoid.Running I would instead get the magnitude of the velocity of the players RootPart. If the player is shoved or falls Running will not fire, that is if you want this result. Vector.Magnitude gives you the magnitude of the Vector, this is essentially the size of the Vector and is a single number. You can scale your UI based off this value.