I’m trying to use dust particles when a player is running with shift, right now you can sprint and the particles work but they stay active when you’re jumping or falling. I need to know how to know when the players is running on the ground so I can only use them then
You can just check if they’re holding the shift key, or if that’s not an option check the players walk speed.
I’m already checking the speed, but the speed stays the same when they’re in the air or falling so the particles stay enabled
They’d likely hold shift while jumping, when running your jump height is increased
You’d simply need to script a service for when the key is pressed down (left shift in this case)
local UserInputService = game:GetService(“UserInputService”)
– Shift keys
local shiftKeyL = Enum.304.LeftShift
then you can alter what it does (like particles) when its pressed!
– Handle user input began differently depending on whether a shift key is pressed
local function Input(input, gameProcessedEvent)
if not IsShiftKeyDown() then
– Normal input
else
– Shift input
UserInputService.InputBegan:Connect(Input)
What if you check if they are on the ground and holding shift
I know that i’m trying to only enable the particles when the character is running on the ground
I have no idea how but I would
You can use Humanoid:GetState
in order to see if the player’s current state is either Enum.HumanoidStateType.Running
or Enum.HumanoidStateType.RunningNoPhysics
. On top of this, you can see if the player is moving by checking the Humanoid.MoveDirection.Magnitude
.
If the player has a humanoid state of Enum.HumanoidStateType.Running
or Enum.HumanoidStateType.RunningNoPhysics
and their current MoveDirection.Magnitude
is not 0, then they are currently running.
well you have two options check the distance from the character to the ground or setup a touched event on the ground the fires a remote event
I tried the running and runningnophysics but ddint try the magnitude thing, that didnt work before but this might
Ok so you’d take an example like the code above, and then you need to detect the ground, in something like this:
if Humanoid then
if Humanoid.FloorMaterial == Enum.Material.SmoothPlastic then
(next lines would be adding something like the "if not ShiftKeyDown() then)
(and then you add your inputs)
– Normal input
else
– Shift input
the SmoothPlastic here is the ground-you would replace this with whatever ground material if you have.
is there really no way to simply tell when a character is moving and not jumping or falling without going through all of this out of the way hacky stuff
You can just do something like this.
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local running = Enum.HumanoidStateType.Running
local runningNoPhysics = Enum.HumanoidStateType.RunningNoPhysics
game:GetService("RunService").RenderStepped:Connect(function()
local currentState = humanoid:GetState()
local moveDirMag = humanoid.MoveDirection.Magnitude
if (currentState == running or currentState == runningNoPhysics) and moveDirMag > 0 then
print("player is running")
end
end)
Just a bit of feedback on your post, I would suggest surrounding your code in tildes (`), simply add three of them before and after your code, then tell it the langauge. (ignore the dash (-), it was just so it didn’t automatically go into it)
-```lua
-```
so you end up with
if Humanoid then
if Humanoid.FloorMaterial == Enum.Material.SmoothPlastic then
end
end