How to Make a *POLISHED* Sprint and Stamina System in Roblox Studio (2023)
ฝัง
- เผยแพร่เมื่อ 8 มิ.ย. 2024
- In this video you'll learn how to create a sprint system with stamina and animations using character attributes!
-- BIG ANNOUNCEMENT --
My studio's game is nearing completion, but we need YOU to test the game and give feedback! By joining the Roblox group and Discord server, you'll gain access to unique rewards only given to testers!
Game Link: www.roblox.com/games/15143143...
Discord Server: / discord
Group Link: www.roblox.com/groups/3325056...
-- Timestamps --
Intro 0:00
Assigning Players Stats 0:06
Setting up Input 2:19
Setting up Stamina 4:15
Setting up Stamina Recharge 6:02
Creating the Stamina UI 9:05
Stamina UI Script 10:57
Adding Animations 12:49
Stopping Player Movement 14:04 - ยานยนต์และพาหนะ
If if you enjoyed this video and want to support me then don't forget to try my game with the link in the description! I was trying a different style of video where I explain what I'm doing after doing it, so let me know in the replies what you thought of that and any questions you may have.
This is great!
On mobile the animation doesn’t work, also on pc whenever I use shift while standing the animation plays when I’m not moving. Other than that great video!
Great video, though when I implement the animation feature it doesn't work. And it doesn't show any red errors in the output about it..
@@misteryious his doesn’t work, so I made my own, when making put it on a loop or you’ll have to keep copy and pasting the animations
@@StillCodedownload RealismMod plugin, it has a ton of options including disable shiftlock
You should definitely keep doing these kinds of tutorials. You explaining what everything is doing actually makes me learn something!
Best tutorial ever! Thank you so much.
Bro this is an insane tutorial! Thank you so much for the help! You are a freaking legend! Definitely underated! I spent 2 hours tryna figure this out and i came across this vid! LIFESAVER!!
For the ppl that say they hold shift when they stay still and the animation still plays just put this under the print(stamina)
if humanoid.MoveDirection.Magnitude
THANK YOU SO MUCH BRO YOU SAVED MY GAME
Tysm
I’ve been trying to find a video where they show how to add walking and running animations separately, this video helped me
trying to learn lua, great video explains everything and i can just copy what i dont get
totally subbing
This is actually good replication techniques and a good tutorial compared to alot in the community nice work!
can you make the next vid about how to make a skill tree + skill points system (and levels if u want) (but only if u want to)
Thanks this video is super underrated now i can finally make a horror game
bro this helped me so much beascuase my code was right. but I didn't known you had to set the scale first.
18th like from me. Keep making good content sir.
10:29 you can fix that by changing the green bars anchor point, rotating ui in roblox causes issues sometimes and it’s unreliable
the legend is back
Haha thanks man, I hope you enjoy!
when i freeze while i run the runninganim is still going, how do i fix that?
I did everything exactly how it says, but im getting and error that says "Begin is not a valid member of Enum.UserInputType" at line 9
is there a way to when you sprint the FOV changes?
how would i change the remaining size to go right to left instead of up to down?
how do i make other actions take stamina as well? dashing or rolling for example
hey your videos are really helpful. I have confronted a problem; when I run out of stamina completely it pauses for about 5 seconds before I start to regenerate stamina. Is there a solution for this problem?
i dont know why but when i press shift when i idle the animation play, how can i fix this?
When I press Shift it just makes me COMPLETLY stop and I cant walk anymore. I can only jump
sup dude its zeke w vidoe
should do a video doing a menu system like when a player presses M or a keybind a gui with like differant stuff it in
Yooo, thanks dude. A menu system is a good idea, I'll add that to my to-do list.
can you make the same thing but you also loose stamina when you jump?
bro if i hold shift when i say animation is playing how fix it?
bro iu stoped after 4 mins where u said test when i pressed shift i couldnt move at all i checked and everything was exactly the same i tried with r6 and r 15 none worked
Can you add a dashing system with this aswell?
what if I want stamina to decrease when I jump
can anyone suggest me
for the character config, is it possible to add additional attributes for more options like, mana points, vitality points, for additional game mechanics?
Absolutely! Attributes are a very flexible way of controlling any kind of system you want to make.
How did you get animations of the marketplace? What?!
could you do a video on working on stuff 2d related like a 2 camera that works smoothly
That's a good idea. Just like a 2D platformer, right?
@@ManlyCreator yea since thats the type of game im maing
@@thatonechannel990 It might be a while before I make a video like that, but if you need it soon I'd recommend checking out my top-down camera video. All you need to do is change the camera angle and it would work the exact same 👍
How to make the stamina bar horizontal without it bugging out
I was wondering if it was possible to add wait(5) somewhere before it actually starts to recharge. Or make it so that once stamina reaches 50 or halway on the bar, it allows you to run again.
maybe u could add a timer before the stamina regen event starts
yeah i did that for 2 seconds till recharge but i made it so you could still sprint even if 1 second had passed but it wouldn't regen ur stamina
Hey, im new to roblox studio, and this video is teaching me a lot, but for some reason, the game isnt applying the attributes to my character when I try testing it? I copied what you write letter for letter, but still nothing. Either way, again, thanks for the video!
Nevermind, I was checking the wrong file, it works for now!
W
why is my map uncolided i was falling forever
what happens to the stamina draining when you have different fps? do you drain more or less stamina depending on your fps
That's a really good question and I'm glad you brought that up. Players with a lower framerate would have a higher advantage since they would have less stamina subtracted each second. To fix this, use the equation (staminaUsage * 60 * delta) in place of just subtracting or adding staminaUsage. 60 assumes a base rate of 60 fps and delta is the time between each frame. Let's say a player's fps is 30, then the delta is going to be 0.03 (twice the delta of someone with 60 fps), therefore doubling the stamina used to balance out their usage with other players. Hope that makes sense.
That really feels like an ai generated response lol@@ManlyCreator
no model?
Can you make a version where the stamina bar only appears when your sprinting?
I'm not sure, but I think you can change the visibility or transparency of the gui or frames when the player is sprinting. I haven't tested this out, but you can try!
The player still sprints even when the leftShift button is released. It only stops when the stamina runs out. Same for the animation. Is there a way to fix this?
The player won't play the animation too. Please help.
Thank you.
you need input ended function,
try this: UserInputService.InputEnded:connect(function(input)
if input.keycode == enum.keycode.(your key)
then character.Humanoid.WalkSpeed = "your base walkspeed"
sprintanim(youranimation):stop()
For some reason the attributes wont add to the humanoid :/
same problem
Help when I was testing when I pressed shift my player stoped all I could do is jump and when I released shift it still wouldn’t move
Would you mind showing me your script?
problem started at 4:05 i am having the same problem and this is my script :
character config:
local module = {
BaseWalkSpeed = 16,
SprintSpeed = 32,
Stamina = 100,
MaxStamina = 100
}
return module
player data:
--Services--
local RS = game.GetService("ReplicatedStorage")
-- Settings--
local characterConfig = require(RS.Configuration.CharacterConfig)
--Script--
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for stat, value in characterConfig do
character.Humanoid:SetAttribute(stat, value)
end
end)
end)
SprintClient:
--Services --
local CAS = game:GetService("ContextActionService")
--script--
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local function sprint(actionName, inputState, inputType)
if inputState == Enum.UserInputState.Begin then
humanoid.WalkSpeed = humanoid:GetAttribute("SprintSpeed")
elseif inputState == Enum.UserInputState.End then
humanoid.WalkSpeed = humanoid:GetAttribute("BaseWalkSpeed")
end
end
CAS:BindAction("Sprint", sprint, true, Enum.KeyCode.LeftShift )
if humanoid.MoveDirection.Magnitude
I cant move at all i can jump but thats it
how would i get the ui to fade off screen if im not sprinting
i was trying to do that but i couldn't come up with a way to
I've copied everything exactly, but it won't work. why?
Any errors?
How do I make the make the user stop sprinting when he has stopped moving but still holding shift?
For this you would have to do constant checks with the RunService. If you join my Discord and contact me I can give you better assistance.
if humanoid.MoveDirection.Magnitude
@@ziggykidder8861 Thank god ur a life saver
why does it say walkspeed is not a valid member of humanoid? please help
it may be because u typed it wrong, in script its not walkspeed its WalkSpeed(with capitals) and its not humanoid its Humanoid
for some reason it wont work for me when i test at 4:13
Same
You must type humanoid.WalkSpeed with a uppercase S
local function sprint(actionName, inputState, inputType)
if inputState == Enum.UserInputState.Begin then
humanoid.WalkSpeed = humanoid:GetAttribute("SprintSpeed")
elseif inputState == Enum.UserInputState.End then
humanoid.WalkSpeed = humanoid:GetAttribute("BaseWalkSpeed")
end
end
This was my problem, idk about yours.
He did not show how to not make it so you dont play the anim while not moving so just add this in the SprintClient right before "Print(Stamina)"
if humanoid.MoveDirection.Magnitude
goodlooks wouldn't have figured it out
Thank you so much, but now if I hold shift before moving the animation doesn't plays at all,
It only plays if i'm already moving and then hold shift, any clues on fixing that?
How would i code the ui if I made it horizintal
humanoid:GetAttributeChangedSignal("stamina"):Connect(function()
local stamina = humanoid:GetAttribute("stamina")
remaining.Size = UDim2.new( (stamina / maxStamina), 0, 1, 0 )
end)
thanks!@@testdoang6161
thx dawg ❤ @@testdoang6161
@@testdoang6161 Thx so much
i cant see it ( am i blind??)
why didnt it add the attributes? (i checked and everything was the same)
did you add the comas after the numbers in the module script?
1:57
@@SVNNYYT i did but it still wouldnt work, any other solution?
my stamina isnt draining
nvm, I put :GetAttribute not :SetAttribute
YOUR studio 🤔🤔🤔
whenever i set the rechargeTime below 0.5 the stamina does not regen anymore, and i want to make the stamina regen slower, any help?