The issue is sometimes when I am double jumping the ui that shows how many double jumps I have left disables and then if I double jump again it restarts the double jumps so it makes me jump more!
What solutions have you tried so far?
Finding a solution!
local userInput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local char = player.Character
player.CharacterAdded:Connect(function(c)
char = c
end)
local jumpEvent = script.Parent.Jumped
local animation = script:WaitForChild("Boost")
local anim = char.Humanoid:LoadAnimation(animation)
local upgradeEvent = script.Parent.Upgrade
local background = script.Parent.Background
local bar = background.Bar
local label = script.Parent.Label
local maxJumps = player.DJumps.MaxDJumps.Value
local jumpsLeft = maxJumps
local onGround = false
local debounce = false
coroutine.resume(coroutine.create(function()
while wait(.1) do
local ray = Ray.new(char.HumanoidRootPart.Position, Vector3.new(0,-3,0))
local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{char})
if hit then
onGround = true
bar:TweenSize(UDim2.new(1,0,1,0),
Enum.EasingDirection.InOut,
Enum.EasingStyle.Quad,
.1
)
maxJumps = player.DJumps.MaxDJumps.Value
char.Humanoid.JumpPower = 50
script.Parent.Enabled = false
bar.Visible = true
jumpsLeft = maxJumps
label.Text = jumpsLeft.." / "..maxJumps
else
Vector3.new(0,-4,0)
wait(0.1)
onGround = false
end
end
end))
upgradeEvent.Event:Connect(function(newValue)
maxJumps = newValue
end)
jumpEvent.Event:Connect(function()
if onGround == false then
script.Parent.Enabled = true
end
if jumpsLeft > 0 and char and debounce == false then
if onGround == false then
debounce = true
jumpsLeft -= 1
label.Text = jumpsLeft.."/"..maxJumps
char.Humanoid.JumpPower = 50
bar:TweenSize(UDim2.new(jumpsLeft / maxJumps,0,1,0),
Enum.EasingDirection.InOut,
Enum.EasingStyle.Quad,
.1
)
if jumpsLeft == 0 then
delay(.1, function()
bar.Visible = false
end)
end
char.Humanoid.JumpPower = 125
anim:Play()
char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
delay(0.3, function()
debounce = false
end)
end
end
end)
userInput.JumpRequest:Connect(function()
jumpEvent:Fire()
end)
local double = false
game:GetService("UserInputService").JumpRequest:Connect(function()
if double == false and game.Players.LocalPlayer.Character.Humanoid:GetState() == Enum.HumanoidStateType.FreeFall then
double = true
game.Players.LocalPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end)
game.Players.LocalPlayer.Character.Humanoid.StateChanged:Connect(function()
if game.Players.LocalPlayer.Character.Humanoid:GetState() == Enum.HumanoidStateType.Landed then
end)
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
local JMP = 80 -- jumppower of doiblejump
local originalJMP = 50 -- the normal jumppower
local canDoubleJump = false
local hasDoubleJumped = false
function onJumpRequest()
if not character or not humanoid or not character:IsDescendantOf(workspace) or
humanoid:GetState() == Enum.HumanoidStateType.Dead then
return
end
if canDoubleJump and not hasDoubleJumped then
hasDoubleJumped = true
humanoid.JumpPower = JMP
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
humanoid.StateChanged:Wait()
humanoid.JumpPower = originalJMP
end
end
local function characterAdded(newCharacter)
character = newCharacter
humanoid = newCharacter:WaitForChild("Humanoid")
humanoid.StateChanged:connect(function(old, new)
if new == Enum.HumanoidStateType.Freefall then
canDoubleJump = true
end
end)
end
if localPlayer.Character then
characterAdded(localPlayer.Character)
end
localPlayer.CharacterAdded:connect(characterAdded)
UserInputService.JumpRequest:connect(onJumpRequest)
I copied it from the tutorial lol, was too lazy
Put the localscript in StarterPlayer - starterplayerscripts
The thing is I have like a different way of that script because in my game you can buy more jumps so if a player buys some more jumps then the value of the jumps goes up!
I’ve edited the code so that you can do that, you have the original JMP of player and the upgraded jumppower of doublejump, the making of the “upgrading jumppower double jump” is you need to script.
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
function onJumpRequest()
if not character or not humanoid or not character:IsDescendantOf(workspace) or
humanoid:GetState() == Enum.HumanoidStateType.Dead then
return
end
if canDoubleJump and not hasDoubleJumped then
hasDoubleJumped = true
humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
local function characterAdded(newCharacter)
character = newCharacter
humanoid = newCharacter:WaitForChild("Humanoid")
hasDoubleJumped = false
canDoubleJump = false
oldPower = humanoid.JumpPower
humanoid.StateChanged:connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower
elseif new == Enum.HumanoidStateType.Freefall then
wait(TIME_BETWEEN_JUMPS)
canDoubleJump = true
end
end)
end
if localPlayer.Character then
characterAdded(localPlayer.Character)
end
localPlayer.CharacterAdded:connect(characterAdded)
UserInputService.JumpRequest:connect(onJumpRequest)