I want to have a jetpack that flies. This has already been done. It works by the player holding the jump button to activate the server-sided script. However, when you are falling down your moment carries, making the jetpack only slow you down. To fix this, I made the character jump every time the jetpack activates, therefore negating the falling.
My kinda working script & video to jetpack, but it spams itself
robloxapp-20200624-1614245.wmv (692.9 KB)
function onJump()
if canJetpack then
local j = hum.Jump
isFlying = j
Fire("Space", j)
if j then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
end
hum:GetPropertyChangedSignal("Jump"):Connect(onJump)
Now, the problem is that because the character jumps, the jetpack function calls itself, making the character jump again, and on and on, basically spamming the server.
I made a script which tries to debounce it. It works, (as shown in the start of the video), but if a player spams the jump button the jetpack is activated multiple times, throwing them up even after it’s done.
My (failed) Script and video when I tried to debounce the jump (so it doesn't auto spam)
robloxapp-20200624-1600274.wmv (1.1 MB)
function onJump()
if canJetpack and not isDelay then
local j = hum.Jump
if j then
if not isDelay then
print("started")
isFlying = true
Fire("Space", true)
isDelay = true
hum:ChangeState(Enum.HumanoidStateType.Jumping)
wait(0.1)
isDelay = false
end
else
print("finished")
isFlying = false
Fire("Space", false)
end
end
end
hum:GetPropertyChangedSignal("Jump"):Connect(onJump)
My reaction to this: OMG I exploited myself!
I either need an alternative to stop the character’s fall, or a working way to “debounce”