Alright so, there’s this peculiar thing that happens when I go ahead and subtract 0 from 50. The expected result should be 50, correct? However, ROBLOX turns it into a 49 regardless. I am awfully confused in general.
Code:
-- get game services
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local plrs = game:GetService("Players")
-- define short-hand references for rlua stuff
local plr = plrs.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hume = char:WaitForChild("Humanoid")
-- define short-hand references for related ui elements
local icon = script.Parent:WaitForChild("Icon")
local cdnum = icon:WaitForChild("Number")
-- define variables
local isJumping = false
local original = hume.JumpPower
local amountToLower = 0
local cooldown = 0
local constCooldown = 3
--
local function loadChar(new)
char = new;
hume = char:WaitForChild("Humanoid")
hume:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if hume.FloorMaterial == Enum.Material.Air and isJumping then isJumping = false end
end)
end
-- if this is an actual character, then call loadChar
if plr.Character then
loadChar(plr.Character)
end
-- attatch a function that initializes everything required when a character is added
plr.CharacterAdded:Connect(function(new)
amountToLower = 0
cooldown = 0
original = hume.JumpPower
loadChar(new)
end)
-- detect whether or not a player is jumping when a jump-request is sent
uis.JumpRequest:Connect(function()
if hume.FloorMaterial ~= Enum.Material.Air and not isJumping then
isJumping = true
amountToLower = math.clamp(amountToLower + 2, 0, original)
if amountToLower > 0 then cooldown = constCooldown end
end
end)
spawn(function()
while wait() do
if cooldown > 0 and amountToLower > 0 then
repeat cooldown = math.clamp(cooldown - 0.1, 0, math.huge); wait(0.1) until cooldown == 0
end
end
end)
spawn(function()
while wait() do
if cooldown == 0 and amountToLower > 0 then
repeat amountToLower = math.clamp(amountToLower - 1, 0, original); wait(0.25) until (amountToLower == 0 or cooldown > 0)
end
end
end)
-- core code required for drawing the UI and making it not look terrible
spawn(function()
while wait() do
if hume then
if icon and cdnum then
if amountToLower > 0 then
hume.JumpPower = original - amountToLower
cdnum.Text = tostring(hume.JumpPower)
end
end
end
end
end)
Place to see the effects:
https://www.roblox.com/games/6674572793/untitled-cube-game