I scripted a DataStore script using https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317. The script worked at first, but then it suddenly stopped working. Both scripts are located in ServerScriptService, and now I am receiving an error in the output: ServerScriptService.Game.Server.DataStoreManager:38: attempt to index upvalue 'userData' (a number value).
--[[
author: 8_zn
--]]
--//Services\\--
local Players = game:GetService("Players")
local serverScriptService = game:GetService("ServerScriptService")
local replicatedStorage = game:GetService("ReplicatedStorage")
--//Module\\--
local dataStore2 = require(serverScriptService:WaitForChild("Game"):WaitForChild("Modules"):WaitForChild("DataStoreModule"))
--//Events\\--
local eventsFolder = replicatedStorage:WaitForChild("Events")
local updateCurrencyEvent = eventsFolder:WaitForChild("UpdateCurrencyEvent")
--//Script\\--
local function setupUserData()
local userData = {
Currency = {
["Fossil"] = 0;
};
Dinosaur = {
["Tyrannosaurus Rex"] = false;
["Allosaurus"] = false;
["White Terror"] = false;
};
}
return userData
end
Players.PlayerAdded:Connect(function(Player)
local userDataStore = dataStore2("UserData", Player)
local userData = userDataStore:Get(setupUserData())
local function updateClientCurrency()
local fossilAmount = userData["Currency"]["Fossil"]
updateCurrencyEvent:FireClient(Player, fossilAmount)
end
updateClientCurrency(userData)
userDataStore:OnUpdate(updateClientCurrency)
end)
Thank you!

1 comment
I have solved it myself by changing the function name to "updateData" (I don't understand why changing the name worked lol)