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

How do i add to my charging script a limit?

Asked by 6 years ago

I need help with adding to this cript a limit (Like if you charge you charge charge charge and then it stops when the value of the ki is 100):

local plr = game.Players.LocalPlayer;
repeat wait(1) until plr.Character;
local char = plr.Character;
local mouse = plr:GetMouse();
local down = 0;
local charging = 0;
local cd = 1;
local max = script:WaitForChild("MaxKi");
local Ki = plr.PlayerGui:WaitForChild("Ki");
local Cost = script:WaitForChild("Cost");
local maxxing = 0;
local hum = char.Humanoid

function effect()
local AuraClone = game.Lighting.ChargingAura:Clone()
AuraClone.Parent = char.Torso
end

function effectend()
local CloneAura = char.Torso.ChargingAura
CloneAura:Remove()
end

local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and not gp then
if input.KeyCode == Enum.KeyCode[script.Key.Value] then
if cd == 1 then
if plr.Character.Humanoid.Health > 0 then
if Ki.Value < max.Value then
down = 1;
effect();
end;
end;
end;
end;
end;
end);

UIS.InputEnded:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and not gp then
if input.KeyCode == Enum.KeyCode[script.Key.Value] then
down = 0;
effectend();
end;
end;
end);


while wait() do
if down >= 1 then
if plr.Character.Humanoid.Health > 0 then
if Ki.Value > 0 then
Ki.Value = Ki.Value + Cost.Value;
charging = charging + 1;
end;
end;
end;
end;
0
no need to put end; just use end abnotaddable 920 — 6y
0
Why do you use semicolons but no whitespace lol. This isn't the 80s Pejorem 164 — 6y

1 answer

Log in to vote
0
Answered by
Pejorem 164
6 years ago
local function recharge(hum, rate, limit)
    while hum.Health > 0 and hum.Health + rate <= limit do
        hum.Health = hum.Health + rate
    end
end
0
What does this mean? MajinBluee 80 — 6y
0
It just repeats an addition until it reaches the upper limit or seeps the lower limit Pejorem 164 — 6y
0
Explain your answer in English. Don't just post code; this doesn't help the poster or the community understand why the code does what it does. hiimgoodpack 2009 — 6y
0
It wasn't a fully developed piece of code so I put as much effort into the explanation as I did the code aha. My apologies Pejorem 164 — 6y
Ad

Answer this question