No. Im not asking you guys to write a script for me. Im just asking for a guidance on how one would achieve something like this. Im not really good at constructing script especially when things get complex. So far i’ve already made this.
The script
local WorkspacePlayer = game:GetService("Players).LocalPlayer.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local Energy = 60
local function SetSpeed(Speed)
local human = WorkspacePlayer:FindFirstChild("Humanoid")
if human then
human.WalkSpeed = Speed
end
end
local Run = coroutine.create(function() -- Exhaust energy while running
while true do
wait(1)
Energy = Energy - 1
end
end)
local StopRun = coroutine.wrap(function() -- Regenerate energy
coroutine.yield(Run)
SetSpeed(16)
wait(1)
while Energy < 60 do
Energy = Energy + 1
wait(0.25)
end
coroutine.yield()
end)
local CheckEnergy = coroutine.wrap(function() -- When energy deplete
while true do
if Energy == 0 then
coroutine.resume(StopRun)
end
end
end)
UIS.InputBegan:Connect(function(Key,Bool)
if Bool then return end
if Key == Enum.KeyCode.LeftShift then
SetSpeed(25)
coroutine.resume(Run)
CheckEnergy()
end
end)
UIS.InputEnded:Connect(function(Key,Bool)
if Bool then return end
if Key == Enum.KeyCode.LeftShift then
coroutine.resume(StopRun)
end
end)
of course this script doesn’t work. As this is made in few go, and im already run out of idea on how to do this efficiently. Any criticsm on what should i do to make it work would really help me alot. I need some guidance on how people do this. I’ve only thinked to use coroutine but im really new at it so give me some tips about coroutine.
Yea this post is a little bit weird