Easy Written By I_amCapitalT

Basic Player Leaderstats Created on: 01-01-2019

The basics of Player's leaderstats code.

Leaderstats - Event and Leaderstats

This code will tell you about the basic variables and events when the player is added to the game

-- Lessson 1/3: Event and Variable

game.Players.PlayerAdded:Connect(function(plr)
	local lds = Instance.new("Folder") -- The object that is defined as Stats
	lds.Name = "leaderstats" -- Name of the Object
	lds.Parent = plr -- Parent of the object
	
end)

Leaderstats - Currencies/Values

The code below will show the other part of the first code.

-- Lessson 2/3: Stats and Value Objects
game.Players.PlayerAdded:Connect(function(plr)
	local lds = Instance.new("Folder") -- The object that is defined as Stats
	lds.Name = "leaderstats" -- Name of the Object
	lds.Parent = plr -- Parent of the object
	
	local stat1 = Instance.new("IntValue") -- You can use any of the Value Objects such as: IntValue, NumberValue, etc.
	stat1.Parent = lds -- This object is parented with lds(leaderstats)
	stat1.Name = "Stat" -- Name of the Object
	stat1.Value = 0 -- If you're giving the value as 0 no need to add statname.Value = num
end)

Leaderstats - Adding More Stat Values

This will show how you can Add more Statistics using Lesson 2

-- Lessson 3/3: New Stats
game.Players.PlayerAdded:Connect(function(plr)
	local lds = Instance.new("Folder") -- The object that is defined as Stats
	lds.Name = "leaderstats" -- Name of the Object
	lds.Parent = plr -- Parent of the object
	
	local stat1 = Instance.new("IntValue") -- You can use any of the Value Objects such as: IntValue, NumberValue, etc.
	stat1.Parent = lds -- This object is parented with lds(leaderstats)
	stat1.Name = "Stat" -- Name of the Object
	stat1.Value = 0 -- If you're giving the value as 0 no need to add statname.Value = num
	
	local stat2 = Instance.new("StringValue") -- You can use any of the Value Objects such as: IntValue, NumberValue, etc.
	stat2.Parent = lds -- This object is parented with lds(leaderstats)
	stat2.Name = "Stat2" -- Name of the Object
	stat2.Value = "StringValue" -- This can be strings, or even numbers
end)

Hope this will help the Beginners with Lua. Thank you, I_amCapitalT

Easy Written By I_amCapitalT

See I_amCapitalT's profile on Roblox

Discussion