Script not detecting when character is jumping

Hello!
I’m working on a smash bros game and I already have most of the things setup already for the game

One of the things I haven’t setup yet is a double jump, which I started doing a few days ago
The problem is that, the script I have for my double jump doesn’t work with my custom character selection.

I have a GUI to select characters, and basically all it does it when a player picks a character, it copies the character from ReplicatedStorage and sets that as the player’s character, then it copies all the scripts which are also in ReplicatedStorage and puts them in the character.

The script works if I place it within the starter character, but not if it’s in the custom character. I also messed around with the print function in my script and found out that the problem is that the script doesn’t detect when a player requests to jump, or when the humanoid state is changed

Can anyone help me figure out whats wrong? Also sorry for the lenghty post, this is my first post and I wanted to make sure it covered everything !

local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

if character.Name == "Builderman" then
	print("A")
end

local MAX_JUMPS = 2
local TIME_BETWEEN_JUMPS = 0.2
local numJumps = 0
local canJumpAgain = false

humanoid.StateChanged:Connect(function(oldState, newState)
	if Enum.HumanoidStateType.Landed == newState then
		numJumps = 0
		canJumpAgain = false
	elseif Enum.HumanoidStateType.Freefall == newState then
		wait(TIME_BETWEEN_JUMPS)
		canJumpAgain = true
	elseif Enum.HumanoidStateType.Jumping == newState then
		canJumpAgain = false
		numJumps += 1
	end

end)

game:GetService("UserInputService").JumpRequest:Connect(function()
	if canJumpAgain and numJumps < MAX_JUMPS then
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
end)

Put some variables (depends if you already put them) let me know if it works for you

local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local Character = player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local canJump = false
local MAX_JUMPS = 2
local numJumps = 0

local function StateChanged(oldState, newState)
	if Enum.HumanoidStateType.Landed == newState then
		numJumps = 0
		canJump = false
	elseif Enum.HumanoidStateType.Freefall == newState then
		wait(0.2)
		canJump = true
	elseif Enum.HumanoidStateType.Jumping == newState then
		canJump = false
		numJumps += 1
	end
end

local function JumpRequest()
	if canJump and numJumps < MAX_JUMPS then
		Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
end

Humanoid.StateChanged:Connect(StateChanged)
UserInputService.JumpRequest:Connect(JumpRequest)

I modified it a bit because I remember using a double jump script before
I think the problem is that the scripts are copied, why dont you leave them in StarterCharacter? no matter the character you choose, you will always have a double jump

Thanks for replying !

why dont you leave them in StarterCharacter? no matter the character you choose, you will always have a double jump

I’m not sure if you mean the starter character itself or StarterCharacterScripts, but either way leaving the scripts in either one would not give it to the custom character, as it is swapping the player’s current character and deleting the old one which wouldn’t add the script to it