the scripts work in both R6 and R15
#1 Sprint without stamina
Create a local script in StarterPlayerScript
The Script:
local uis = game:GetService("UserInputService")--User Input Service
local db = false --debounce
local tw = game:GetService("TweenService")--Tween service
local info = TweenInfo.new(0.2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0) --tween info
local tween = tw:Create(workspace.CurrentCamera,info,{FieldOfView = 90}) --Starting Tween
local tweenBack = tw:Create(workspace.CurrentCamera,info,{FieldOfView = 70}) --Ending Tween
local SprintKey = Enum.KeyCode.LeftControl --Sprint Key
uis.InputBegan:Connect(function(key)--User Press Button
if key.KeyCode == SprintKey then--Detect if player pressed spring Key
db = true--set debounce to true
while wait() do--loop
if db == true and game.Players.LocalPlayer.Character then--detect if player have a character or not and if db = true
repeat wait() until game.Players.LocalPlayer.Character.Humanoid--wait for humanoid
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 22--set walk speed to 22 "you can change that"
tween:Play()--play the start tween
break
else
break
end
end
end
end)
uis.InputEnded:Connect(function(key)--User Stop Pressing The Button
if key.KeyCode == SprintKey then--Detect if player stoped holding pressed spring Key
db = false--set debounce to false
if game.Players.LocalPlayer.Character then--detect if player have a character
repeat wait() until game.Players.LocalPlayer.Character.Humanoid--wait for humanoid
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16--set player speed to 16 "Normal Speed"
tweenBack:Play()--Play the back tween
end
end
end)
#2 Sprint with stamina
First Step:
Create a local script in StarterPlayerScript
The Script:
local uis = game:GetService("UserInputService")--User Input Service
local db = false --debounce
local tw = game:GetService("TweenService")--Tween service
local info = TweenInfo.new(0.2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0) --tween info
local tween = tw:Create(workspace.CurrentCamera,info,{FieldOfView = 90}) --Starting Tween
local tweenBack = tw:Create(workspace.CurrentCamera,info,{FieldOfView = 70}) --Ending Tween
local SprintKey = Enum.KeyCode.LeftControl --Sprint Key
uis.InputBegan:Connect(function(key)--User Press Button
if key.KeyCode == SprintKey then--Detect if player pressed spring Key
db = true--set debounce to true
while wait() do--loop
if db == true and game.Players.LocalPlayer.Character then--detect if player have a character or not and if db = true
repeat wait() until game.Players.LocalPlayer.Character.Humanoid--wait for humanoid
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 22--set walk speed to 22 "you can change that"
tween:Play()--play the start tween
break
else
break
end
end
while db == true do--detect if db == true
if game.Players.LocalPlayer.Stamina.Value > 0 then--detect if player stamina > 0
game.Players.LocalPlayer.Stamina.Value = game.Players.LocalPlayer.Stamina.Value - 1 --dicrease player stamina
else
db = false--if player stamina < of = to 0 db will set to false
break
end
wait()
end
if db == false and game.Players.LocalPlayer.Stamina.Value < game.Players.LocalPlayer.MaxStamina.Value then--detect if db == false
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16--set player speed to normal speed "16"
tweenBack:Play()--play back tween
end
end
end)
uis.InputEnded:Connect(function(key)--User Stop Pressing The Button
if key.KeyCode == SprintKey then--Detect if player stoped holding pressed spring Key
db = false--set debounce to false
if game.Players.LocalPlayer.Character then--detect if player have a character
repeat wait() until game.Players.LocalPlayer.Character.Humanoid--wait for humanoid
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16--set player speed to 16 "Normal Speed"
tweenBack:Play()--Play the back tween
while db == false and game.Players.LocalPlayer.Stamina.Value < game.Players.LocalPlayer.MaxStamina.Value do
wait()
game.Players.LocalPlayer.Stamina.Value = game.Players.LocalPlayer.Stamina.Value + 1
end
end
end
end)
Second Step:
I recommend you to check this Ui Scale and Size Tutorial or use this Plugin
Create new Gui
you can put the “StaminaBackFrame” To what ever you like
The “StaminaFrame” Size should be (1,0,1,0) and the position should be (0,0,0,0)
it should be a script inside a Ui elemant inside a back frame
in the local script past this script:
local StaminaBackFrame = script.Parent.Parent--get BackFrame
local StaminaFrame = script.Parent--get StaminaFrame
local Player = game.Players.LocalPlayer--get Player
local Stamina = Player:WaitForChild("Stamina")--get Player Stamina
local MaxStamina = Player:WaitForChild("MaxStamina")--get Player MaxStamina
local function refresh()--Function refresh
script.Parent.Size = UDim2.new(Stamina.Value/MaxStamina.Value,0,1,0)--send stamina frame size
end
Stamina.Changed:Connect(function() --detect if Stamina changed
refresh() --call the function
end)
MaxStamina.Changed:Connect(function() --detect if MaxStamina changed
refresh() --call the function
end)
Third Step:
Make a new Script in Server Script Service
Past This in:
game.Players.PlayerAdded:Connect(function(Player)--Detect if a player joined the gamed
local MaxStamina = Instance.new("IntValue",Player)--add maxstamina to tha player Instance
MaxStamina.Name = "MaxStamina"
MaxStamina.Value = 50--Set the player max Stamina
local Stamina = Instance.new("IntValue",Player)--add stamina to tha player Instance
Stamina.Name = "Stamina"
Stamina.Value = MaxStamina.Value--Make The player stamina = to maxstamina
end)