Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i detect a player jump with a script?

Asked by 4 years ago

Hello everyone, I am currently working on a game with a friend, and i am trying to make a script that increases a variable with 1 each time the character jumps. The problem is i dont know how to detect a jump with a script. Ive tried it with spacebar, but you can just spam spacebar, and it wouldnt work on mobile and console. So how do i make a jump detector script?

1 answer

Log in to vote
1
Answered by
EmK530 143
4 years ago
Edited 4 years ago

https://developer.roblox.com/en-us/api-reference/class/Humanoid

There is a humanoid event that is called Jumping which fires when the Jumping state enables and disables, there is also a bool from the event which indicates if the player is jumping or not.

The script below only works for localscripts, it might work for serverscripts if you fix the local Player value.

local Player = game.Players.LocalPlayer

Player.CharacterAdded:Wait()

local Character = Player.Character

local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.Jumping:Connect(function(bool)
    if bool == true then
        print(Player.Name .. " is now jumping.")
    else
        print(Player.Name .. " is no longer jumping.")
    end
end)

I have been unable to test this script so please let me know if I did something wrong so I can correct it

Thanks to Glacitron for line 2

0
it should work but one problem, the character might not always exist in time, remember we have to do character = localplayer.Character or localplayer.CharacterAdded:Wait() Glacitron 239 — 4y
0
Put in StarterGui. PrismaticFruits 842 — 4y
0
It detects the jumps, but i added another non local variable to the local script (i placed the script in playerstarterscripts btw), and i want to do the current jumps variable + 1 each jump and make the gui text in the StarterGui that variable. But it doesnt work, also placing the script in startergui doesnt work, it doesnt work at all then. KillPower05 0 — 4y
Ad

Answer this question