local classDataStore = dataStoreService:GetDataStore('ClassDataStore', 'Test')
local remotes = replicatedStorage:WaitForChild('Remotes')
local functions = remotes:WaitForChild('Functions')
local equipClass = functions:WaitForChild('EquipClass')
local classData = {}
function equipClass.OnServerInvoke(player, class)
for i, v in pairs(classData) do
if v[1] == player.UserId then
for _, table in pairs(v[2]) do
if table == class then
return true
else
return false
end
end
end
end
end
function dataManager:GetData(player)
local playerClasses = {player.UserId, {'Knight', 'Archer'}}
local loadedClasses = classDataStore:GetAsync(player.UserId .. '-classes')
if loadedClasses ~= nil then
playerClasses[2] = loadedClasses
end
table.insert(classData, playerClasses)
end
Basics of this script. Setups up the players classes when they join, and the function at the top (equipClass) basically fires whenever a player tries to equip a class. If they have the class saved then it returns true, otherwise it returns false.
On this line:
local playerClasses = {player.UserId, {'Knight', 'Archer'}}
It sets what classes a player owns. So every player owns those two classes, for free. But when I try the equip function, it only returns true for the Knight class and not Archer. Have I entered something wrong on the above line?? Not entirely sure if this is the most efficient way to go about saving multiple items in a data store either (as there will eventually be 10+ classes) so if there is a better way then any info would be great