Hello, I don’t understand what currentplayer is, or any of the last part of the script for that matter. The devhub keeps introducing new things and its hard to keep up
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
Is currentplayer a variable which has been declared IN the for loop? can you even do that
currentplayer is the name given by to whoever wrote that code for the ilerator return of a for loop. In this case, this for loop is an incremental loop going from 1 to the amount of players in the game, used to do a specific thing in this case.
for loops follow this guideline
for (variablename) = (starting number), (ending number) do
--End
end
You can name the variable anything you want, most people call it i
CurrentPlayer is just the index for where the for loop reached.
I don’t get why people do it this way, possibly because it’s somewhat faster than a for i, v loop, or just beginner’s method.
--this
local player = playerlist[currentplayer]
--is just
local player = playerlist[index] --index for example can be "1" which will represent the first value in the table.
A count loop? What do you mean? A for loop is already technically a count loop, you can do anything with that number, I only made it just print as an example
That’s what I was saying in that example, it’ll print all of them at once since there’s no wait, I wrote it like that to show the order in which they’ll print
Yes, technically it’d go through the loop fast enough that it’d loop pretty instant, they’d just be on new lines. the output to his example would legit just be