we are working on stamina for jumping, we want to take away 10 stamina for each jump.
However, there is no clear way to tell (why?) when a roblox character jumps.
work off keypress - this works, using User Input Service and detecting which key was pressed. Trouble is, it will only remove for the first jump, if you hold the jump key down (spacebar). We need -10 each jump
work off humanoid property changed signal - this takes off MANY -10 stamina points, because for a SINGLE JUMP it enters the âjumpâ state 9 or 10 times⌠(why?!)⌠we checked it with a print statement attached to the humanoid.changed.
Is there any clear way to tell each time a roblox character jumps (counting each jump as only â1â jumpâŚbut counting each and every jump ?)
So why does it print âfloor materialâ as a humanoid changed property?
And why in the MIDDLE of the jump, when he touches nothing but air?
???
Please donât post anything you haven 't used yourself. There are tons of answers we have tried from the forums already that didnât workâŚplease donât repost anything you havenât used)*
Weâve been troubleshooting this a while. thanks !
you can try doing something along the lines of this
all you have to do is adjust the âTricky_Time_I_Need_To_Figure_Outâ variable until it looks natural
local uis = game:GetService("UserInputService")
local Holding_Space = false
local Tricky_Time_I_Need_To_Figure_Out = 2
--determine when player tries to jump
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
Holding_Space = true
end
end)
--determine when player releases jump key
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
Holding_Space = false
end
end)
--this doesnt need to be wrapped in a coro if you dont want
coroutine.resume(coroutine.create(function()
while true do
if Holding_Space == true then
--subtract 10 stamina
wait(Tricky_Time_I_Need_To_Figure_Out)
else
wait(.1)
end
end
end))
Thanks very much for the response. Unfortunately, we are looking for something more exact than guessing the number of seconds for a jump. A game engine should know when a jump begins and ends; we are certain roblox must have an accurate way to count jumps because it would be bizzaro world if you couldnât tell when your character began and ended a jump in a game engine. We appreciate your help, thanks ~!
Could you not attach a :GetPropertyChangedSignal(âJumpedâ) onto the Humanoid object in the character? I remember this not working right server-side so you might need to use this on the client.
Like so:
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then Humanoid = Instance.new("Humanoid") Humanoid.Parent = Character
Humanoid:GetPropertyChangedSignal("Jumping"):Connect(function()
if Humanoid.Jumping then
-- They jumped!
end
end)
The FloorMaterial is a property that indicates the material on which the humanoid is standing (Terrain and parts). You can utilize this property to track instances where the humanoid is in the air. Alternatively, you can track the humanoidâs jump state and ensure that only one of these occurrences is counted.
repeat task.wait(.1) until game:GetService("Players").LocalPlayer.Character and game:GetService("Players").LocalPlayer.Character.Humanoid
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if Humanoid:GetState() == Enum.HumanoidStateType.Jumping then
print("Look they are jumping rn how exciting!")
end
end)
Thank you for your response! Sorry friend, as stated in original post, this actually triggers MANY times on a single jump.
Out put looks like this, if I use a print statement to print the humanoid property every time it changes, it prints the below, FOR A SINGLE JUMP:
Jumped
Jump Replicated
Jumped
Jumped
Jump Replicated
Jumped
Floor Material
This means it takes 10 from Stamina many times for a single jump.
Thank you for your response.
For future responses, please only respond with tested possibilities. The forum is full of answers that did not work when tested. Thank you for your response !
I think property changed singalling that FloorMaterial would work as you suggested @ali432567 to be honest, as that wonât change multiple times, unlike Jump.
You could do some verification by signalling a remote when a jump is detected (when FloorMaterial is Enum.FloorMaterial.Air) via a RemoteEvent then handling some stuff on the server, for example, you could store when a player last jumped on the server and whether their âjumpâ is valid? Donât think detecting jump is replicated to the server to be honest, think itâs a client-owned thing.
local Humanoid = script.Parent:WaitForChild("Humanoid")
Humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
print("Player jumped")
end
end)
i tested it and it should work. it prints one time per jump and also accounts for holding spacebar.
the issue isnât an exploiter firing a remote the issue is it not firing since it reduces stamina exploiters would make it not fire and not lose stamina
Thanks - we did some pseudocode on a clipboard and some research, and are going to work this direction. If we get it to work we will let you know. We are basically going to:
watch for humanoid property to change, once it does:
check if global isAlreadyJumping is false, if so, check if humanoid is jumping, if so:
set isAlreadyJumping to true (special debounce global)
remove 10 from stamina
â
if humanoid state changes, and isAlreadyJumping is true,
check if humanoid property is âfloor materialâ
if its floor material, check if its âairâ
if is not air, set global isAlreadyJumping to false
thatâs what we are trying - tomorrow. let you know if it works.
Then using methods to detect the player jumping as suggested isnât a possibility, as that would be the ultimate source of truth to detect whether a player jumped.
Itâs sketchy, and I wouldnât advocate these methods by all means, but you could detect it on the server, you could check to see whether theyâre so much off of the ground, or if the character is touching something other than the parts it owns/in its hierarchy? But all of these arenât accurate, as you could technically jump on the Z or X axis in world space depending on if you have a rotated world, and as for the touching parts, if you had a ceiling, it would detect as you not jumping suddenly.