Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How should I make a run script that runs out after a certain amount of time?

Asked by 7 years ago

I was trying to make a sprintscript and I completed it, but I am not sure how to make it so that you run out of energy after you use it for a certain amount of time then after you use it up it regenerates after a certain amout of time how shal i go about that?

regular script:

function onPlayerEntered(player) repeat wait () until player.Character ~= nil local s = script.SprintScript:clone() s.Parent = player.Character s.Disabled = false player.CharacterAdded:connect(function (char) local s = script.SprintScript:clone() s.Parent = char s.Disabled = false
end) end

game.Players.PlayerAdded:connect(onPlayerEntered)

local script:

local mouse = game.Players.LocalPlayer:GetMouse() local running = false

function getTool()
for _, kid in ipairs(script.Parent:GetChildren()) do if kid.className == "Tool" then return kid end end return nil end

mouse.KeyDown:connect(function (key) -- Run function key = string.lower(key) if string.byte(key) == 48 then running = true local keyConnection = mouse.KeyUp:connect(function (key) if string.byte(key) == 48 then running = false end end) for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (70+(i2)) wait() end game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30 repeat wait () until running == false keyConnection:disconnect() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (80-(i2)) wait() end end end)

0
You see that Lua button on the right of the bold C? Press it and paste your code in the box created. Thanks. Rodmane234 85 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Maybe try something like this?

local energy = 100
while wait(1) do
    if running == true then
        energy = energy - 1
    end
    if energy >1 then
        running = false
    end
    if running = false then
        energy = energy + 1
    end
end
0
How would I import that into the script? @spyro10jf r0blox1053 3 — 7y
Ad

Answer this question