Hello, in this script why did I need to Instance.new a folder called leaderstats? Just for me to insert the IntValue? Surely I can just insert the IntValue into the player?
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)
while true do
wait(1)
local playerlist = Players:GetPlayers()
for currentPlayer = 1, #playerlist do
local player = playerlist[currentPlayer]
local points = player.leaderstats.Points
points.Value = points.Value + 1
end
end```
A folder named leaderstats (or anything in the player called leaderstats) is required inorder to display the leaderboard you see that is combined with the player list. Without it, it won’t display a points leaderboard. They probably made it because they wanted a leaderboard to be made using Roblox’s default leaderboard system
It’s just used as a way to contain the current stats of a player. They used an IntValue because they wanted to contain a integer stat into the leaderboard. The name of the Value is what’ll show up in the ledaerboard and the Value of it is the number under it that’ll show up. You can use other Values to store in a leaderboard, usch as NumberValues and StringValues
intvalues have a property that is a number and depending on where you put it can be accessed by any script! this can help you access important numbers that more then one script can use its kind of a variable that only stores numbers
--heres an example
local intVal = workspace.IntValue
intValue.Value = 10-- the IntValue has a property named value that takes a number
-- another script
local intVal = workspace.IntValue
wait(2)-- i put wait so the other script can change the Val first
print(Int.Value)
Easiest way to think about it, is that it’s just an Object representation of a Integer value. How-ever it becomes an Instance at this point and has things such as .Name, .Parent, and methods that are known to class type “Instance” along with custom properties “Value”; :GetPropertyChangedSignal(“Value”):Connect( Is a nice feature you get when using Object IntValue, or any off the other Value typed Objects.
That is correct I believe, not sure you replied to the person though haha.
Athough I would recommend using .Changed for BaseValues as it is shorter and also returns the new value of the BaseValue, although I only recommend it for BaseValues as for other instances it’s not that good to use
.Changed is good, I’ve just ran into instances where .Changed doesn’t fire and :GetPropertyChangedSignal(“Value”) does, so I’ve stuck more with the latter. (my knowledge is completely test based and that maybe fixed by now)