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

Walking time counter not working(?)

Asked by 1 year ago
Edited 1 year ago

So basically, i'm trying to count the total walking time a player has made and print it, but it just prints 0 or numbers that have nothing to do with the total walking time.

The script is a LocalScript parented to a NumberValue, which value is supposed to be the total walking time.

local StateType = Enum.HumanoidStateType
local agility = script.Parent.Value
local plr = game.Players.LocalPlayer
local agilitygain = 0

local function AddAgility()
    if plr.Character.Humanoid:GetState() == StateType.Running then
        while wait(0.1) do
                if plr.Character.Humanoid.MoveDirection.Magnitude > 0 then
                    agilitygain +=0.1
                else
                    agility = agility+agilitygain
                print("AgilityGain is:",agilitygain)
                print("Agility is:",agility)
                agilitygain = 0
                agility = script.Parent.Value
                    break
                end
        end

        end
    end
plr.Character:WaitForChild("Humanoid").Running:Connect(AddAgility)

Any help would be appreciated :)

1 answer

Log in to vote
0
Answered by 1 year ago

I'm not an expert at this sort of thing, so try work with this and adapt it to make a proper script:

local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:Wait() or plr.Character
local count = 0
local hum = char:WaitForChild("Humanoid")

while wait(.1) do
    if hum.MoveDirection ~= Vector3.new(0,0,0) then
        count += 1
        print(count)
    end
end

Hope this helps in any way at all.

Ad

Answer this question