JumpRequest Bug!

What im trying to do
When the player Jump the humanoid JumpPower/JumpHeight Value increases

What is the issue
Everyting works fine but when i jump it do this :
robloxapp-20200805-1648025.mp4 (989.8 KB)
Here is a screenshot :

If you dont understand the character just spam jump in mid air and he never fell back until i stop holding space bar .

Here is the script of the client :

while wait(1) do -- I have done this  so it doesn't spam de Remote Event
	if player.Character.Humanoid.MoveDirection.Magnitude >0 then -- This is for the speed training
		game.ReplicatedStorage.SpeedEvent:FireServer(player)
	end
end
UIS.JumpRequest:Connect(function() -- This is for the Jump training
	game.ReplicatedStorage.JumpEvent:FireServer(player)
end)

Here is the Server Script :

game.ReplicatedStorage.JumpEvent.OnServerEvent:Connect(function(player)
	local debounce = game.ServerStorage.Debounces[player.Name]
	if not debounce.Value then
		debounce.Value = true
		player.StatsFolder.JumpValue.Value = (player.StatsFolder.JumpValue.Value + 1)
		player.Character.Humanoid.JumpHeight = (player.StatsFolder.JumpValue.Value / 2)
		wait(1)
		debounce.Value = false
	end
end)

I searched for long time how to fix it but i didn’t find one Thank you !
-VokarouYT

Dont loop the connection without disconnecting it (plus you dont have to loop it?)

Also, jump request usually fires multiple times when jumping. It doesnt fire once as usual if you were expecting that

1 Like

Upon initial analysis, this code is going to get buggy and probably pretty laggy very quickly.

Lets start by fixing your client script.

while wait(1) do -- I have done this  so it doesn't spam de Remote Event
	if player.Character.Humanoid.MoveDirection.Magnitude >0 then -- This is for the speed training
		game.ReplicatedStorage.SpeedEvent:FireServer(player)
	end
	
-- THIS IS THE PROBLEM LINE VVVV
	UIS.JumpRequest:Connect(function() -- This is for the Jump training
		game.ReplicatedStorage.JumpEvent:FireServer(player)
	end)
end

The spot I outlined as a “problem” is definitely going to be a problem for you. Firstly, you’re adding a new event listener EVERY SECOND. This means if that event happens, you could potentially have millions of events firing. The solution to that is to move this:

UIS.JumpRequest:Connect(function() -- This is for the Jump training
		game.ReplicatedStorage.JumpEvent:FireServer(player)
	end)

Outside the while loop.

As for what else you are trying to accomplish, can you please elaborate? The language used as well as what you want to do is a bit confusing.

Thanks!

1 Like

Everything works fine but the problem is that my character spam jump in the air .
:slight_smile: