Hi guys,
I am making post to see if there are any improvements that can be made to my script (which I am sure there are).
Basically it is a Charged Jump script; If the player holds space for more than 1 second then their Jump is twice as strong, if they hold it for less than a second then their jump is normal.
The script functions as it should, but I feel like there are plenty of improvements that can be made to it, but I just don’t know what they are.
Here is the full script:
Summary
local lastCharge
local chargeAcknowledged = false
UIS.InputBegan:Connect(function(input, gameProcessed)
if StateTracker.State == "onRunning" then
if input.KeyCode == Enum.KeyCode.Space then
humanoid.JumpPower = 0
if chargeAcknowledged == false then
if StateTracker.State == "onRunning" then
chargeAcknowledged = true
lastCharge = time()
end
end
print(chargeAcknowledged)
local timeCheck
while UIS:IsKeyDown(Enum.KeyCode.Space) do
chargeAcknowledged = false
timeCheck = time() - lastCharge
print(timeCheck)
wait(.1)
if timeCheck >= 1 then
humanoid.JumpPower = 100
elseif timeCheck < 1 then
humanoid.JumpPower = 50
end
end
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
end)
StateTracker.State is what I use instead of HumanoidStateType; it is basically the same thing and in the script I am checking if the Player is on the ground
I added while UIS:IsKeyDown(Enum.KeyCode.Space) do because I was unsure of another way of checking how long Space was being held down for. (this is where I believe the biggest change can be made)