Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i add to my charging script a limit?

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;

2 comments

0

no need to put end; just use end

0

Why do you use semicolons but no whitespace lol. This isn't the 80s

1 answer

local function recharge(hum, rate, limit)
	while hum.Health > 0 and hum.Health + rate <= limit do
		hum.Health = hum.Health + rate
	end
end

4 comments

0

What does this mean?

0

It just repeats an addition until it reaches the upper limit or seeps the lower limit

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.