Hello,
So you are probably going to be disappointed in me for saying that I free modeled a double jump script, which is understandable. I tested it out and it actually worked quite well, so I decided I would try to spice it up by changing the numbers around and adding sound and an animation for the second jump (a front flip).
Things went badly after the sound and number change and after trying many different things for about half an hour, I still couldn’t get past an error that prevented me from loading the animation in the humanoid, and therefore it couldn’t play. The error said, “attempted to locate a nil value.” I am completely lost with this script. How can I load the animation to the humanoid?
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.15
local DOUBLE_JUMP_POWER_MULTIPLIER = 1.6
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)
script.Woosh:Play()
--animation:Play() goes here, but how am i supposed to load it??
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)
Thanks!