So essentially, I have a script ServerScriptService. Inside this script, there's a function for when a player is added, and within that a function for when character is added. In the character added function, another function is called outside of both functions, called RandomFunction, that tracks how many steps the player takes, which works fine. The problem is, when there is more than one player in the game, only one player's steps are being tracked. If that player stops moving, the next player to move will have their steps tracked, and it will continue to track only their steps until they stop moving and someone else starts moving.
The question is, will I have to move the script somewhere? I'm not keeping track of stats locally then firing a remote to update the stats globally because that would cause too many remotes to fire based on how often the stat is updated. What am I to do?
Thank you!
edit (code): (NOTE: This is under ServerScriptService)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
repeat wait() until player.Character
player.CharacterAdded:Connect(function(char)
randomfunc(char, player)
print('Char added function loaded')
end)
end)
function randomfunc(charac, player)
print('Random function for steps added loaded')
local stepStat = player.leaderstats["Steps Taken"]
charac.Humanoid.Running:Connect(function(speed)
local newWalking = speed >= 1
if newWalking == walking then return end --no change
walking = newWalking
while walking do
wait(.3)
stepStat.Value = stepStat.Value + 1
end
--print(walking)
end)
end

2 comments
Why workspace.ChildAdded?
it detects more parts, it iterates more and unlike character added, the character loads once but parts can detect more..