Player not jumping when I force them to

I want the player to be able to hold space, and when they release it, they jump higher depending on how long they held it for.

Nothing happens at all when you begin pressing space or when you release.

FYI, I’m using ContextActionService to check when the player presses space

Video:
https://gyazo.com/e004298bba8357a2ee034127a1add3ea

Code:

-- // Variables
local PlayersHolding = {}

-- // Functions
local function Jump(Humanoid)
	local b = true
	print("Jump")
	if b then
		Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		b = false
		task.wait(2)
		b = true
	end
end

local function RemoteFired(Player, InputState)
	print(Player, InputState)
	if InputState == Enum.UserInputState.Begin then
		table.insert(PlayersHolding, Player)
		
		Player.Character.Humanoid.JumpPower = 0
		
		while table.find(PlayersHolding, Player) and task.wait(0.15) do
			Player.JumpPower.Value += 1
		end
		
	elseif InputState == Enum.UserInputState.End then
		for i,v in pairs(PlayersHolding) do
			if v == Player then
				Player.Character.Humanoid.JumpPower = Player.JumpPower.Value
				
				Jump(Player.Character.Humanoid)
				
				table.remove(PlayersHolding, i)
				
				Player.Character.Humanoid.JumpPower = 0
				Player.JumpPower.Value = 0
				
				break
			end
		end
	end
end

-- // Connections
JumpRemote.OnServerEvent:Connect(RemoteFired)

:ChangeState is very buggy when done on the server, if you could fire a remote event back to the client with :ChangeState, I’m fairly sure it would work.

Also you don’t need those variables in your jump function, you can just do this:

local function Jump(Humanoid)
	Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end

You can use Humanoid.Jump = true instead for a serverside solution.

I had tried that, and it literally does not work at all. Plus I’ve already marked the post as solved by the first reply.

Interesting. That might be a different issue, but it works completely fine on my end.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.