I want to make a researching system, but my code it not working.
local dataStore = game:GetService("DataStoreService"):GetDataStore("Researching#T100")
local RE = game.ReplicatedStorage.RemoteEvents.ResearchComplete
local purchaseResearches = {
["Purchase Cost 1"] = {
["Percent"] = 2.5,
},
["Purchase Cost 2"] = {
["Percent"] = 5,
},
["Purchase Cost 3"] = {
["Percent"] = 10,
},
}
local cocoaExchangeResearches = {
["Cocoa Exchange 1"] = {
["Percent"] = 5,
},
["Cocoa Exchange 2"] = {
["Percent"] = 10,
},
["Cocoa Exchange 3"] = {
["Percent"] = 25,
},
["Cocoa Exchange 4"] = {
["Percent"] = 50,
},
}
game.Players.PlayerAdded:Connect(function(plr)
pcall(function()
local researchFolder = Instance.new("Folder",plr)
researchFolder.Name = "Researching"
-- Sub-Research Folders
local purchaseFolder = Instance.new("Folder",researchFolder)
purchaseFolder.Name = "Purchase Costs"
local cocoaExchangeFolder = Instance.new("Folder",researchFolder)
cocoaExchangeFolder.Name = "Cocoa Exchanges"
-- Getting each research
for i, v in pairs(purchaseResearches) do
local newPurchaseCost = Instance.new("NumberValue",purchaseFolder)
newPurchaseCost.Name = v
newPurchaseCost.Value = v["Percent"]
print("Success")
local newPurchaseCompleted = Instance.new("BoolValue",newPurchaseCost)
newPurchaseCompleted.Name = "Completed"
newPurchaseCompleted.Value = false -- making sure the value is false
print("Success")
end
for _, x in pairs(cocoaExchangeResearches) do
local newCocoaExchange = Instance.new("NumberValue",cocoaExchangeFolder)
newCocoaExchange.Name = x
newCocoaExchange.Value = x["Percent"]
print("Success")
local newCocoaExchangeCompleted = Instance.new("BoolValue",newCocoaExchange)
newCocoaExchangeCompleted.Name = "Completed"
newCocoaExchangeCompleted.Value = false -- making sure the value is false
print("Success")
end
local data = nil
data = dataStore:GetAsync(plr.UserId)
if data ~= nil then
for i, v in pairs(researchFolder:GetDescendants()) do
if v.ClassName == "NumberValue" then
v.Completed.Value = data[v.Name]
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
pcall(function()
local researching = plr:WaitForChild("Researching")
if researching then
local data = {}
for i, v in pairs(researching:GetDescendants()) do
if v.ClassName == "NumberValue" then
data[v.Name] = v.Completed.Value
end
end
dataStore:SetAsync(plr.UserId, data)
end
end)
end)
All I saw in the explorer was this:
And I got nothing in the output.
Why is this not working?