How to make a steps counter? (also my leaderstats is having issues)

I’m asking for help on how to do the step counter because

  • I’m new to coding and dont know much
  • I cannot find anything about this topic on youtube or here
    Heres my leaderstat code thats being buggy and kicking me i cannot figure out the problem

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	local Money = Instance.new("IntValue")
	Money.Name = "Money"
	Money.Parent = leaderstats

	local Steps = Instance.new("IntValue")
	Steps.Name = "Steps"
	Steps.Parent = leaderstats
	
	local Stage = Instance.new("IntValue")
	Stage.Name = "Stage"
	Stage.Parent = leaderstats

	local data

	local success, message = pcall(function()
		data = DataStore:GetAsync(plr.UserId .. "-Data")
	end)

	if success then
		if data then
			Money.Value = data
		end
	else
		warn(message)
		plr:Kick("Error while retrieving your data.")
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local data = plr.leaderstats["Money"].Value

	local success, message = pcall(function()
		DataStore:SetAsync(plr.UserId .. "-Data", data)
	end)

	if not success then
		warn(message)
	end
end)

this is a screenshot of the problem (leaderstats)

1 Like

in the output what is the yellow text printed?

omg i am stupid i forgot to enable api

Do you think you can help with step counter?

like when you move it goes up (the leaderstat)

You would need to check the humanoid state by using GetState() and checking if the returned value is HumanoidStateType.Running and then adding 1 to the steps value. All in a while loop of some sort

uhhhhhhhhhhhhhh im confused local script or script how do i do a loop

i have too many questions about it

normal script inside the datastore script

loop: while task.wait() do inside that put the statements about checking the state etc

I could try write it up but currently i’m not home so i’m in mobile which is a pain

Ok i will try this when i wake up because its 3 in the morning