Hey i am trying to learn Roblox scripting .And i have some problem.Can you explain this for me?
I can’t understand it.This code i got from here:Scoring Points | Roblox Creator Documentation
Here is it, the code which is the problem make me feel tired because i don’t understand it.
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players") -- Getting players service
local function onPlayerAdded(player)
local leaderstats = Instance.new("Folder") -- creating folder
leaderstats.Name = "leaderstats" -- naming it 'leaderstats'
leaderstats.Parent = player -- putting folder to player
local points = Instance.new("IntValue") -- creating int value
points.Name = "Points" -- naming it 'Points'
points.Value = 0 -- setting value of Points
points.Parent = leaderstats -- putting it to leaderstats
end
Players.PlayerAdded:Connect(onPlayerAdded) -- function 'onPlayerAdded' will fire, when player joined to game
You have to use that to create a folder that will hold all your stats in, that line of code there makes a folder appear when they join. So they always have leaderstats, since you can’t drag and drop the folder into the player you use that line of code to basically do it for you.
Correct, the folders name MUST be named “leaderstats” with no caps or mispelling or it won’t correctly run. The values inside can be changed to whatever you want though!
It has to be called leaderstats so the menu shows up.
Any other folder that isn’t called “leaderstats” won’t make this show.
You can only name the values inside like in the image I showed they named the IntValue’s name to Gold.