You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m trying to make a rank up system, just like saber simulator and I think that the best way to do that was to use array. -
What is the issue? Include screenshots / videos if possible!
the issue is that, using index += 1 doesn’t seem to add anything to the leaderstats. When I try to print it, it works perfectly and add + 1 to the index. It just doesn’t show on the leaderstats -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried to search on the dev forum for some information but nothing is similar to my problem.
the most important is between the line 1 and 23. the rest is to load the data and save the data (thanks to the dev forum lol)
local dataModule = {}
local rankUpModule = require(game.ReplicatedStorage.ClientServerModules:WaitForChild("RankUpModule"))
local array = {rankUpModule.AllRanks}
for i, v in pairs(array) do
local index
index = i
currentRank = v[index].Name
local testforfun = coroutine.create(function()
while true do
task.wait(5)
index += 1
print(v[index].Name)
end
end)
coroutine.resume(testforfun)
end
function dataModule.addInstance(player: Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local rankValue = Instance.new("StringValue")
rankValue.Name = "Rank"
rankValue.Value = currentRank
rankValue.Parent = leaderstats
local timeValue = Instance.new("IntValue")
timeValue.Name = "Time"
timeValue.Value = 0
timeValue.Parent = leaderstats
local gemValue = Instance.new("IntValue")
gemValue.Name = "Gems"
gemValue.Value = 0
gemValue.Parent = leaderstats
end
function dataModule.saveData(player: Player)
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("DataStore")
local leaderstatsFolder = player:FindFirstChild("leaderstats")
local Key = player.UserId
local data = {
leaderstatsFolder.Time.Value,
leaderstatsFolder.Gems.Value,
leaderstatsFolder.Rank.Value,
}
local success, result
repeat
success, result = pcall(function()
dataStore:UpdateAsync(Key, function()
return data
end)
end)
task.wait()
until success
if not success then
warn("We were unable to save your data, check this for more info: ".. tostring(result))
elseif success then
print("Successfully saved the data for ".. player.Name)
else
warn("An error occurred, check this for more info: ".. tostring(result))
end
end
function dataModule.loadData(player: Player)
local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("DataStore")
local Key = player.UserId
local leaderstatsFolder = player:FindFirstChild("leaderstats")
local timeValue = leaderstatsFolder:FindFirstChild("Time")
local gemsValue = leaderstatsFolder:FindFirstChild("Gems")
local rankValue = leaderstatsFolder:FindFirstChild("Rank")
local data = {
leaderstatsFolder.Time.Value,
leaderstatsFolder.Gems.Value,
leaderstatsFolder.Rank.Value,
}
local success, result
repeat
success, result = pcall(function()
data = dataStore:GetAsync(Key)
end)
task.wait()
until success or not players:FindFirstChild(player.Name)
if success then
timeValue.Value = data[1]
gemsValue.Value = data[2]
rankValue.Value = data[3]
print("Successfully loaded the data for " .. player.Name)
elseif not success then
warn("We were unable to load your data, check this for more info: " .. tostring(result))
else
warn("An error occurred, check this for more info: " .. tostring(result))
end
end
return dataModule