How can I improve this script?

Hello, I am just wondering how I could improve this script.

local stepToGive = 1
local db = false


    game.Players.PlayerAdded:Connect(function(player)
    	local char = player.CharacterAdded:Wait()
    	char.Humanoid.Running:connect(function()
    		if db == false and char.Humanoid.Torso.Velocity.magnitude > 1 then
    			db = true
    			player.leaderstats.Steps.Value = player.leaderstats.Steps.Value + stepToGive
    			wait(1)
    			db = false
    		end
    	end)	
    end)
1 Like

Looks fine to me, you could change if db == false to if not db.

Overall seems like a standard debounce setup.

Also don’t forget to capitalize Connect here: char.Humanoid.Running:connect(function()

EDIT: also in the future there’s a #help-and-feedback:code-review forum.

1 Like

I used a while true do loop so it will check every time when the player is moving. But thanks!