How can I make this script a server script?

Hello, I made a script to increase a player’s agility every second, but I can’t figure out how to make it a server script, so everyone can see the player’s agility leaderstat. My script:

-- // Variables \\ --

local Player = game.Players.LocalPlayer

-- // Functions \\ --

while true do
	wait(1)
	Player.leaderstats.Agility.Value =
		Player.leaderstats.Agility.Value + 1
end

Have you heard of the PlayerAdded event? That’ll fire every time a Player joins the game :open_mouth:

Whenever you create events like these, you should put them in ServerScriptService so they’re secured on the server side:

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

    while true do
        wait(1)
        Agility.Value += 1
    end
end)
1 Like

Thanks so much! It Worked :smiley:

1 Like