Hey I’m currently making a sprint script and i figured I’d create a stamina GUI bar for it aswell, however I’m having some troubles with the TweenService and yes I’ve searched before creating the post.
This is my local script
local insideBar = player:WaitForChild("PlayerGui"):WaitForChild("Hud").Frame.SprintBar.InsideBar
local tweenInfo = TweenInfo.new(
stamina,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,false,0
)
local function TweenFull(percent)
tween:Create(insideBar, tweenInfo,{Position =UDim2.new(0.012, 0,0.115, 0)})
end
local function TweenEmpty(percent)
tween:Create(insideBar, tweenInfo,{Position =UDim2.new(0.009, 0,0.115, 0)})
end
runService.Heartbeat:Connect(function(DeltaTime)
if sprinting then
if stamina > 0 then
stamina = stamina - DrainRate * DeltaTime
TweenEmpty(stamina)
else
sprint(false)
Exhausted = true
end
elseif stamina < 100 then
stamina = stamina + DrainRate * DeltaTime
TweenFull(stamina)
if stamina > RunRefresh then -- we can now run again!
Exhausted = false
if SprintHeld then -- resume running because player is still holding down the sprint key!
sprint(SprintHeld)
end
end
end
end)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
SprintHeld = true
sprint(SprintHeld)
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
SprintHeld = false
sprint(SprintHeld)
end
end)
The tween animation doesn’t work at all, i just want it to pull the ‘insideBar’ down to the value of ‘stamina’ to show the player how much stamina they’ve got but currently the bar just stays still
You never play the tween, so you just created it and doesn’t play, think of them like audio, to play the tween just do local Tween = …
Tween:Play()
or TweenService:Create(…):Play()
Thanks for the reply, I’ve changed my code to suit this however its still not moving, any other ideas? cheers
local runService = game:GetService("RunService")
local insideBar = player:WaitForChild("PlayerGui"):WaitForChild("Hud").Frame.SprintBar.InsideBar
local tweenInfo = TweenInfo.new(
stamina,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,false,0
)
runService.Heartbeat:Connect(function(DeltaTime)
if sprinting then
if stamina > 0 then
stamina = stamina - DrainRate * DeltaTime
tween:Create(insideBar, tweenInfo,{Position =UDim2.new(0.009, 0,0.115, 0)}):Play()
else
sprint(false)
Exhausted = true
end
elseif stamina < 100 then
stamina = stamina + DrainRate * DeltaTime
tween:Create(insideBar, tweenInfo,{Position =UDim2.new(0.012, 0,0.115, 0)}):Play()
if stamina > RunRefresh then -- we can now run again!
Exhausted = false
if SprintHeld then -- resume running because player is still holding down the sprint key!
sprint(SprintHeld)
end
end
end
end)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
SprintHeld = true
sprint(SprintHeld)
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
SprintHeld = false
sprint(SprintHeld)
end
end)