UIS.JumpRequest failing to connect after player death

I have a script that detects when a player jumps:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Cooldown = tick()
local JumpReqConnection

JumpReqConnection = UIS.JumpRequest:Connect(function()
	print("Jump")
end)

However, once I die and try to jump the request stops working. This script is located in StarterPlayerScripts.

PS: If I test this on another game it works? I don’t know what I could have possibly done to break it. The character still jumps, just no request…

1 Like

Because the character being referenced is the old character. Instances under StarterPlayerScripts gets cloned once upon the Player joining to their PlayerScripts and doesn’t reset. An easy fix would be to use StarterCharacterScripts instead, otherwise, newly reference the character and it’s children inside the connection or constantly update your top-level character/humanoid variable(s).

1 Like

This isn’t the issue. Even though the character is being referenced it is not being used in the code snipped, and as I said testing this on other games works perfectly fine… I’m sure I somehow messed something up externally as this is a huge game, but I cannot figure out what I did

1 Like

Whoops. Anyways, I cannot reproduce this. Assuming it is working on another game, are you somehow using a custom character?

1 Like

No, but I do use a custom character loading system.

1 Like

Can you provide a place file / model with only those scripts? I’d love to help but I dislike asking you to debug it step by step. :sweat:

1 Like

Is it possible for you to send (a snippet of) your code? There is another post that I found regarding failing JumpRequest and it seems to be a custom character issue: UserInputService.JumpRequest problem

1 Like

Hold on it’s very hard to strip this game without it completely breaking

1 Like

All good- it’s just a bit hard to debug based off this. Take your time.

1 Like

BrokenGame.rbxl (827.9 KB)

Ignore the backrooms that’s not the game it’s just a spawning area, A lot of things are either broken or don’t make sense but the thing is you can jump and respawn. It prints “Jump” on jump request.

Remove the spawn location from the backrooms model btw…

1 Like

I’m curious, why did you decide to use “JumpRequest” instead of checking the key they pressed? Jump request fires several times for a singular jump- so I’m wondering if theres a specific reason.

For example: this.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input : InputObject, gameproccessedevent : boolean)
	if not gameproccessedevent and input.KeyCode == Enum.KeyCode.Space then
		print("Jump!")
	end
end)

You can always check if the player is alive / character exists through a simple “if” gate.

1 Like

Mobile and console compatibility. I also have custom mobile buttons and connecting all of them would be a nightmare

1 Like

That’s fair. Though, you could also just check the humanoid’s property “jumping”, as unsuccessful jump requests still fire the function unfortunately.

1 Like

I just figured out disabling all the server scritps except for “Script” and making "Script"s code:

game:GetService("Players").PlayerAdded:Connect(function(P)

	wait(1)

	print("A")

	P.CharacterAdded:Connect(function(C)

		print("C")

		C:WaitForChild("Humanoid").Died:Connect(function()

			wait(5)

			P:LoadCharacter()
		end)
	end)

	P:LoadCharacter()
end)

Makes it work again. Hmmmm

1 Like

Weird… I guess you don’t need anymore help…? :sweat_smile:

Ah yes let me delete the functionality of my game to fix jumping!

My only other suggestion would be to move to using successful jumps through checking the “jump” property of the humanoid. It’s fine to handle that on the server side and only provides successful attempts.

Looks like I’m even more wrong. Using “jump” provided the same issues, just in a less-having add support for all consoles-way.

Not sure if you’ve tried something like this, where the event disconnects and reconnects each time the character dies.

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character, Humanoid

local Cooldown = tick()
local JumpReqConnection

local function CharacterAdded(newCharacter)
   if Character then
      Character = nil
      Humanoid = nil
   end
   if JumpReqConnection then JumpReqConnection:Disconnect(); JumpReqConnection = nil end

   Character = newCharacter
   Humanoid = Character:WaitForChild("Humanoid")
   JumpReqConnection = UIS.JumpRequest:Connect(function()
      print("Jump")
   end)
end

if Player.Character then
   CharacterAdded(Player.Character)
end
Player.CharacterAdded:Connect(CharacterAdded)

This didn’t work… I did actually try this, however right after I found the solution:

Solution: Parenting the character to a folder right after spawning makes it do this… Bug maybe?

Did you also try just parenting it to the workspace? Just out of curiosity to see if that works too, as if, like you said, there’s some sort of parenting bug when you respawn a player like that.