KorniakJoin Date: 2013-08-09 Post Count: 3538 |
My objective is to be able to double jump, but you can't double-jump until the cooldown time of 5 seconds is up. Here is what I've got, and I'm stumped.
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
local LastPressed
UserInputService.JumpRequest:connect(function()
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
LastPressed = tick()
humanoid.StateChanged:connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower
elseif new == Enum.HumanoidStateType.Jumping and tick() - LastPressed <= 5 then
wait(TIME_BETWEEN_JUMPS)
canDoubleJump = true
LastPressed = tick()
end
end)
end
Korniak, the antler dude |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
I cannot double jump at all with what I have done.
Korniak, the antler dude |
|
ThedagzJoin Date: 2012-03-10 Post Count: 798 |
Whats the error? |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
Restarted Code:
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
LastPressed = tick()
humanoid.StateChanged:connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower
elseif new == Enum.HumanoidStateType.Jumping and tick() - LastPressed <= 5 then
wait(TIME_BETWEEN_JUMPS)
canDoubleJump = true
LastPressed = 0
end
end)
end
if localPlayer.Character then
characterAdded(localPlayer.Character)
end
localPlayer.CharacterAdded:connect(characterAdded)
UserInputService.JumpRequest:connect(onJumpRequest)
Error is now that it will double jump once, but after that it won't do it again.
Korniak, the antler dude |
|
ThedagzJoin Date: 2012-03-10 Post Count: 798 |
You didn't put a event for the character added function paste this at the very bottom
localPlayer.CharacterAdded:connect(characterAdded) |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
read my restarted code
Korniak, the antler dude |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
and my objective
Korniak, the antler dude |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
bump
Korniak, the antler dude |
|
|
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
local canDoubleJump = false
local hasDoubleJumped = false
local oldPowerlocal TIME_BETWEEN_JUMPS = 0.2local 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)
You're welcome. |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
wow did you not read what i wanted it to do
Korniak, the antler dude |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
OBJECTIVE RESTATED:
I want the player to double-jump with a cooldown of 5 seconds.
Korniak, the antler dude |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
bump
Korniak, the antler dude |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
bump
Korniak, the antler dude |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
bump again
Korniak, the antler dude |
|
|
local UserInputService = game:GetService("UserInputService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local Character
local Humanoid
local DoubleJump = false
local Debounce = false
UserInputService.JumpRequest:connect(function()
if not Character or not Humanoid or not Character:IsDescendantOf(workspace) or Humanoid:GetState() == Enum.HumanoidStateType.Dead then
return
end
if not Debounce then
Debounce = true
if not DoubleJump and Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
local torso = Character:FindFirstChild("Torso")
if torso then
torso.Velocity = Vector3.new(torso.Velocity.X, Humanoid.JumpPower * 1.01, torso.Velocity.Z) DoubleJump = true
end
end
wait(0.3)
Debounce = false
end
end)
local function CharacterAdded(char)
Character = char
Humanoid = char:WaitForChild("Humanoid")
Humanoid.StateChanged:connect(function(_, new) if new == Enum.HumanoidStateType.Landed then DoubleJump = false end end)
Humanoid.Died:connect(function() DoubleJump = false end)end
if LocalPlayer.Character then
CharacterAdded(LocalPlayer.Character)
end
LocalPlayer.CharacterAdded:connect(CharacterAdded)
Just change the debounce to your cooldown. Happy now?
|
|
|
local UserInputService = game:GetService("UserInputService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local Character
local Humanoid
local DoubleJump = false
local Debounce = false
UserInputService.JumpRequest:connect(function()
if not Character or not Humanoid or not Character:IsDescendantOf(workspace) or Humanoid:GetState() == Enum.HumanoidStateType.Dead then
return
end
if not Debounce then
Debounce = true
if not DoubleJump and Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
local torso = Character:FindFirstChild("Torso")
if torso then
torso.Velocity = Vector3.new(torso.Velocity.X, Humanoid.JumpPower * 1.01, torso.Velocity.Z) DoubleJump = true
end
end
wait(5)
Debounce = false
end
end)
local function CharacterAdded(char)
Character = char
Humanoid = char:WaitForChild("Humanoid")
Humanoid.StateChanged:connect(function(_, new) if new == Enum.HumanoidStateType.Landed then DoubleJump = false end end)
Humanoid.Died:connect(function() DoubleJump = false end)end
if LocalPlayer.Character then
CharacterAdded(LocalPlayer.Character)
end
LocalPlayer.CharacterAdded:connect(CharacterAdded)
There 5 second cooldown. Place in StarterPlayerScripts. You owe me one bro.
Like and fave my game plz.
https://www.roblox.com/games/346407590/Distance-Alpha |
|
KorniakJoin Date: 2013-08-09 Post Count: 3538 |
nope
i owe you nothing, plus i probably fixed it myself |
|