I have a double jump script, but for some reason when I die and respawn, it won’t work for a few seconds, but if you wait on respawn it will start working again. this is bad for speedruns all help appreciated!
local script (starter character scripts)
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 = 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)
I was unable to reproduce this on a blank game with only this script running. Maybe it’s a loading pause on your landscape. I’d suggest a fade in respawn to burn up a few moments to finish re-loading the landscape. A good test of this would be with more than one player, to see if that re-load is the problem. Could also have a popup that shows the last progression time. They would need to click to close and then the game starts. Anything to buy you a few moments.
If this is in starter character then why have this:
if localPlayer.Character then
characterAdded(localPlayer.Character)
end
localPlayer.CharacterAdded:connect(characterAdded)
UserInputService.JumpRequest:connect(onJumpRequest)
You can see if a character exists by doing:
local Character = script.Parent
if Character then
-- do stuff
end
This may also reduce the amount of time it takes to work.
If the Character isn’t fully loaded by the time it hits that if “do stuff” will never happen.
Studio is a bit different in this respect to the game updated.
something like this is for sure …
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
Maybe this will help the missing jump load up time.
Note: Every line in that plays a part in waiting for a fully loaded character either way.
It was in starter player before i Posted this thread, but when I set it to starter character it was a lot less frequent. I just forgot to update the script
I fixed it, I put in a script that makes the player jump on spawn which fixes the state issue, it turns out the script was loading, just the state changed was not working on the first jump, so the first jump was the only jump that fails. Thanks for all the help!