So I have this module script in ServerScriptService:
local module = {}
function module.abbreviate(number)
local abbreviations = {
['K'] = 4,
['M'] = 7,
['B'] = 10,
['T'] = 13,
}
local abbreviatedNumber = {}
local text = tostring(math.floor(number))
if #text > 3 then
for i, abbreviation in pairs(abbreviations) do
if #text >= abbreviation and #text < (abbreviation + 3) then
for abbreviation in text:gmatch(".") do
table.insert(abbreviatedNumber, abbreviation)
end
if #text == abbreviation then
return abbreviatedNumber[1]..'.'..abbreviatedNumber[2]..i
elseif #text == (abbreviation + 1) then
return abbreviatedNumber[1]..abbreviatedNumber[2]..i
elseif #text == (abbreviation + 2) then
return abbreviatedNumber[1]..abbreviatedNumber[2]..abbreviatedNumber[3]..i
end
end
end
else
return text
end
end
return module
…and this normal script located as well in ServerScriptService, but when I try to require the module script in this one, it just won’t do anything. Gives no errors.
--//Services
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
--//DataStore
local CurrencyData = DataStoreService:GetDataStore("CurrencyData")
--//Configuration
local CurrencyName = "QuizCoins"
local StartingValue = 0
local Abbreviator = require(game.ServerScriptService.Abbreviate)
Players.PlayerAdded:Connect(function(player)
local UserData
local success, errMsg = pcall(function()
UserData = CurrencyData:GetAsync(player.UserId)
end)
if success then
print("Data loaded for player " .. player.Name)
else warn("Error loading data for player " .. player.Name .. ": " .. errMsg)
end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Currency = Instance.new("IntValue")
Currency.Name = CurrencyName
Currency.Value = Abbreviator.abbreviate(StartingValue) or StartingValue
Currency.Parent = leaderstats
end)
Players.PlayerRemoving:Connect(function(player)
local SavingPath = player.leaderstats:FindFirstChild(CurrencyName)
if not SavingPath then
warn("Player data not found for saving: " .. player.Name)
return
end
local success, errMsg = pcall(function()
CurrencyData:SetAsync(player.UserId, SavingPath.Value)
end)
if success then
print("Data saved for player " .. player.Name)
else
warn("Error saving data for player " .. player.Name .. ": " .. errMsg)
end
end)