hell all, I’m just wondering what the best way for me to detect when a player jumps. A lot of pages suggest humanoid.Jump etc or jumping, but none seem to be working. All i want is to have something fire an event when a player jumps so it lowers their stamina, and im wondering what the easiest way to do this would be
I believe you should use the humanoid.Jumping method. So something like this:
-- lets say your script is in 'StarterCharacterScripts'
local character = script.Parent
local hum = character:WaitForChild("Humanoid")
hum.Jumping:Connect(function(state)
if state == true then -- if humanoid has jumped
-- code
else -- if humanoid has landed (i think)
-- other code
end
end)
There is also another method where you can check the humanoid StateType.
Here’s another example:
-- again let's say your script is in StarterCharacterScripts
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
hum.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then -- if humanoid is currently jumping
-- code
end
end)
this worked, the only gripe i have is that it only works about 1 in 6 tries, as in I could jump 6 times and at least one of those times one of the jumps will not be detected. For me it works fine but for future scenarios I would love a more consistent version
Just a little bit of more research about this, and I think you may find a fix to that small issue. I never really had that kind of issue before with this. I recommend using the Humanoid.StateChanged method as it’s better and is more reliable.
local function OnHumanoidJumping(Active)
if not Active then return end
print("Hello world!")
end
Humanoid.Jumping:Connect(OnHumanoidJumping)
Use the ‘Jumping’ event instead, I’ve never encountered any inconsistencies while using it. The ‘Active’ parameter simply represents if a jump is beginning or ending.
hello, I am still encountering a lot of issues with the .jump and .jumping events and nothing seems to be working consistently or to a decent standard.
local stamina = {}
local Players = game:GetService("Players")
local maxStamina = 100
local function playerJumped(active, player)
if active then print("jumped") end
end
local function func(player)
local stamina = Instance.new("IntValue")
stamina.Value = maxStamina
stamina.Name = "Stamina"
stamina.Parent = player
local char = player.Character or player.CharacterAdded:Wait()
print(char)
print("testOne")
char:WaitForChild("Humanoid").Jumping:Connect(playerJumped)
print("testTwo")
end
Players.PlayerAdded:Connect(func)
return stamina
this is what my code looks like and it is extremely inconsistent, as in it will detect maybe 1 out of 10 jumps where as .jumping would work a good 4 out of 6 times. is there something wrong with this code? Most of it is just for testing purposes and has yet to have any function.