There is a simple issue with your logic. The Running event of the Humanoid is what you want to use. However, you need to use it in a way that's slightly different than you originally intended. Since I don't know what you plan on doing with the knowledge that the player is running, I'll simply provide some examples of what you can do to know whether or not the player is running. As a quick reference, this is the wiki page I'll be referring to. Here are the three things we know about this event:
- It fires when the speed of the player changes.
- It does not fire repeatedly while the player is moving at a consistent speed.
- It fires when the player jumps straight up and down.
I'm assuming that you wish to avoid the running triggering when the player is simply jumping up and down. I also assume you wish to know that the player is running while they are running at a static rate of change. To do this, let's consider a few important facts. If the player jumps straight up, only the y value in their positional vector changes, and, if the player stops moving, their speed is zero. Remember that the argument passed to the function connected to the Running event is the speed at which the player is moving at that time of change. With all this in mind, let's construct a simple setup that allows to, at any time, know if the player is running:
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local is_running = false
humanoid.Running:Connect(function(speed)
if speed > 0 then
is_running = true
else
is_running = false
end
end)
while true do
print(is_running)
wait(3)
end
As you can see, every three seconds, this outputs whether or not you are running. Therefore, if you're wanting to create a point based walking system (for example), you'd only need to have a basic loop that gives points based on whether or not the is_running variable is true. However, this simple system has an issue. It counts jumping straight up as running. While it is true that you can jump forward and be considered running, you're not considered to be running if you're jumping straight up and down. To fix this issue, remember what I said about only the y value of the positional vector changing. Using this information, we can construct a new system that better fits what running looks like:
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
local is_running = false
local y_out_vector = Vector3.new(1, 0, 1)
local last_position = hrp.Position*y_out_vector
humanoid.Running:Connect(function()
local current_position = hrp.Position*y_out_vector
if current_position ~= last_position then
is_running = true
else
is_running = false
end
last_position = current_position
end)
while true do
print(is_running)
wait(3)
end
And you'll notice that, in this new system, we don't even need the speed parameter, since the position evaluation checks whether or not the player moved.
####I hope this helps. Have a great day scripting!
5 comments
http://idownvotedbecau.se/nocode
That is not a valid reason to downvote this kind of question. In this case, he clearly stated what he tried. Instead of being toxic, actually figure out a solution to the problem.
Doesn't matter. There needs to be code anyways. it's possible OP executed his plan incorrectly. Therefore my downvote still remains valid since there is no code. Mind clicking the link that explains in depth. You see, this question is only useful to the asker since the code is not available for us to see, and anyone in the future who looks up this question would have to guess what it is exactly.
I read from the link before I even posted my comment complaining about the downvote. I still believe the downvote was unjustified. The issue was clearly stated, and code would have probably confused, rather than enlightened, other readers.
And how so. Again the question is only useful to the asker, not future readers. You can't really justify that. My downvote is still valid. Period.