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.
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?
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!
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.
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
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.