Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Walking time counter not working(?)

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.