I’ve had an issue for a while now where data would sometimes take ages to load (sometimes 15+ minutes). So I tried rewriting it to where I used " :Get() " less. It works for me in studio but when people join the game I get hundreds of throttling errors like this image below.
Apologies for the long code but I’ve been trying to fix this issue for a while now and I don’t know what else I can do. Is there anything in here that would cause throttling? Or anything to make this more efficient?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ExpLibrary = require(ServerScriptService.ExpLibrary)
local EffectsLibrary = require(ServerScriptService.EffectsLibrary)
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreStats = require(ServerScriptService.DataStore2)
local DataStoreSpins = require(ServerScriptService.DataStore2)
local DataStoreCore = require(ServerScriptService.DataStore2)
local DataStoreBanned = require(ServerScriptService.DataStore2)
local WaitTime = 0.5
local MaxLevel = ReplicatedStorage.GlobalVariables:WaitForChild("MaxLevel").Value
local MaxGold = ReplicatedStorage.GlobalVariables:WaitForChild("MaxGold").Value
local DataModule = require(ServerScriptService.DataModule)
local StatsTable = DataModule.GetStatsData()
local SpinTable = DataModule.GetSpinsData()
local CoreTable = DataModule.GetCoreData()
DataStoreStats.Combine(
"StatData1",
"NewPlayer",
"Level",
"AvilablePoints",
"Strength",
"Durability",
"Stamina",
"Gold",
"Exp",
"InstantSpin",
"Prestige",
"Banned"
)
DataStoreSpins.Combine(
"SpinData1",
"CommonSpins",
"UncommonSpins",
"RareSpins",
"TraitSpins"
)
DataStoreCore.Combine(
"CoreData1",
"Quirk",
"Trait",
"StoredPower"
)
local function Kick(player)
player:Kick "You are permanently banned"
end
local AddedNew = false
game.Players.PlayerAdded:Connect(function(player)
local Statistics = Instance.new("Folder")
Statistics.Name = "Statistics"
Statistics.Parent = player
local Percentage = Instance.new("IntValue")
Percentage.Name = "Percentage"
Percentage.Value = 0
Percentage.Parent = Statistics
local DataLoaded = Instance.new("BoolValue")
DataLoaded.Name = "DataLoaded"
DataLoaded.Value = false
DataLoaded.Parent = Statistics
local Control = Instance.new("StringValue")
Control.Name = "Control"
Control.Value = "Keyboard"
Control.Parent = Statistics
local PVP = Instance.new("BoolValue")
PVP.Name = "PVP"
PVP.Value = true
PVP.Parent = Statistics
local TitleVisibility = Instance.new("BoolValue")
TitleVisibility.Name = "TitleVisibility"
TitleVisibility.Value = true
TitleVisibility.Parent = Statistics
local MaxStamina = Instance.new("NumberValue")
MaxStamina.Name = "MaxStamina"
MaxStamina.Value = 20
MaxStamina.Parent = Statistics
local CurrentStamina = Instance.new("NumberValue")
CurrentStamina.Name = "CurrentStamina"
CurrentStamina.Value = 20
CurrentStamina.Parent = Statistics
---------------------------------------------------------------------
spawn(function()
local StatData = DataStoreStats("StatData1", player):Get(StatsTable)
local LevelStore = DataStoreStats("Level", player)
local AvilablePointsStore = DataStoreStats("AvilablePoints", player)
local StrengthStore = DataStoreStats("Strength", player)
local DurabilityStore = DataStoreStats("Durability", player)
local StaminaStore = DataStoreStats("Stamina", player)
local GoldStore = DataStoreStats("Gold", player)
local ExpStore = DataStoreStats("Exp", player)
local InstantSpinStore = DataStoreStats("InstantSpin", player)
local PrestigeStore = DataStoreStats("Prestige", player)
local BannedStore = DataStoreStats("Banned", player)
for i, v in pairs(StatsTable) do
local Name = i
if StatData[Name] == nil then
AddedNew = true
print("AddingNewValue ".."("..Name..")")
DataStoreStats(Name, player):Get(v)
task.wait(WaitTime)
end
end
if AddedNew == true then
StatData = DataStoreStats("StatData1", player):Get()
AddedNew = false
end
local InstantSpin = Instance.new("BoolValue")
InstantSpin.Name = "InstantSpin"
InstantSpin.Value = StatData["InstantSpin"]
InstantSpin.Parent = Statistics
InstantSpin.Changed:Connect(function()
InstantSpinStore:Set(InstantSpin.Value)
end)
if not MarketplaceService:UserOwnsGamePassAsync(player.UserId, 72733138) then
InstantSpin.Value = false
end
local Banned = Instance.new("BoolValue")
Banned.Name = "Banned"
Banned.Value = StatData["Banned"]
Banned.Parent = Statistics
Banned.Changed:Connect(function()
BannedStore:Set(Banned.Value)
task.wait(1)
if Banned.Value == true then
Kick(player)
end
end)
if Banned.Value == true then
Kick(player)
end
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Value = StatData["Level"]
Level.Parent = Statistics
local AvilablePoints = Instance.new("IntValue")
AvilablePoints.Name = "AvilablePoints"
AvilablePoints.Value = StatData["AvilablePoints"]
AvilablePoints.Parent = Statistics
local Strength = Instance.new("IntValue")
Strength.Name = "Strength"
Strength.Value = StatData["Strength"]
Strength.Parent = Statistics
local Durability = Instance.new("IntValue")
Durability.Name = "Durability"
Durability.Value = StatData["Durability"]
Durability.Parent = Statistics
local Stamina = Instance.new("IntValue")
Stamina.Name = "Stamina"
Stamina.Value = StatData["Stamina"]
Stamina.Parent = Statistics
local Gold = Instance.new("IntValue")
Gold.Name = "Gold"
Gold.Value = StatData["Gold"]
Gold.Parent = Statistics
Gold.Changed:Connect(function()
if Gold.Value > MaxGold and player.UserId ~= 84689107 then
Gold.Value = MaxGold
end
GoldStore:Set(Gold.Value)
end)
local MaxExp = Instance.new("IntValue")
MaxExp.Name = "MaxExp"
MaxExp.Value = Level.Value * 100
MaxExp.Parent = Statistics
local Exp = Instance.new("IntValue")
Exp.Name = "Exp"
Exp.Value = StatData["Exp"]
Exp.Parent = Statistics
local Prestige = Instance.new("IntValue")
Prestige.Name = "Prestige"
Prestige.Value = StatData["Prestige"]
Prestige.Parent = Statistics
Prestige.Changed:Connect(function()
PrestigeStore:Set(Prestige.Value)
end)
Exp.Changed:Connect(function()
if Exp.Value >= MaxExp.Value and Level.Value < MaxLevel then
local CarryOver = Exp.Value - MaxExp.Value
Exp.Value = 0
MaxExp.Value = Level.Value * 100
Level.Value += 1
AvilablePoints.Value += 3
if Prestige.Value >= 1 then
AvilablePoints.Value += 1
end
ExpLibrary.PlayerGold(player, 10)
if Level.Value % 50 == 0 then
ExpLibrary.RareSpins(player, 1)
ExpLibrary.TraitSpins(player, 5)
elseif Level.Value % 25 == 0 then
ExpLibrary.UncommonSpins(player, 3)
ExpLibrary.TraitSpins(player, 2)
elseif Level.Value % 10 == 0 then
ExpLibrary.UncommonSpins(player, 1)
ExpLibrary.TraitSpins(player, 1)
elseif Level.Value % 5 == 0 then
ExpLibrary.CommonSpins(player, 1)
ExpLibrary.TraitSpins(player, 1)
else
ExpLibrary.CommonSpins(player, 1)
end
task.spawn(function()
EffectsLibrary.LevelUp(player)
end)
Exp.Value += CarryOver
elseif Exp.Value >= MaxExp.Value and Level.Value >= MaxLevel then
Exp.Value = 0
MaxExp.Value = Level.Value * 100
--ExpLibrary.PlayerGold(player, 100)
Level.Value += 0
task.spawn(function()
EffectsLibrary.LevelUp(player)
end)
end
end)
Level.Changed:Connect(function()
MaxExp.Value = Level.Value * 100
LevelStore:Set(Level.Value)
ExpStore:Set(Exp.Value)
AvilablePointsStore:Set(AvilablePoints.Value)
StrengthStore:Set(Strength.Value)
DurabilityStore:Set(Durability.Value)
StaminaStore:Set(Stamina.Value)
end)
repeat task.wait(1) until DataLoaded.Value == true
print("Loaded!")
while true do
task.wait(15)
ExpStore:Set(Exp.Value)
AvilablePointsStore:Set(AvilablePoints.Value)
StrengthStore:Set(Strength.Value)
DurabilityStore:Set(Durability.Value)
StaminaStore:Set(Stamina.Value)
end
end)
---------------------------------------------------------------------
spawn(function()
local SpinsData = DataStoreSpins("SpinData1", player):Get(SpinTable)
local CommonSpinStore = DataStoreSpins("CommonSpins", player)
local UncommonSpinStore = DataStoreSpins("UncommonSpins", player)
local RareSpinStore = DataStoreSpins("RareSpins", player)
local TraitSpinsStore = DataStoreSpins("TraitSpins", player)
for i, v in pairs(SpinTable) do
local Name = i
if SpinsData[Name] == nil then
AddedNew = true
print("AddingNewValue ".."("..Name..")")
DataStoreSpins(Name, player):Get(v)
task.wait(WaitTime)
end
end
if AddedNew == true then
SpinsData = DataStoreSpins("SpinData1", player):Get()
AddedNew = false
end
local CommonSpins = Instance.new("IntValue")
CommonSpins.Name = "CommonSpins"
CommonSpins.Value = SpinsData["CommonSpins"]
CommonSpins.Parent = Statistics
CommonSpins.Changed:Connect(function()
CommonSpinStore:Set(CommonSpins.Value)
end)
local UncommonSpins = Instance.new("IntValue")
UncommonSpins.Name = "UncommonSpins"
UncommonSpins.Value = SpinsData["UncommonSpins"]
UncommonSpins.Parent = Statistics
UncommonSpins.Changed:Connect(function()
UncommonSpinStore:Set(UncommonSpins.Value)
end)
local RareSpins = Instance.new("IntValue")
RareSpins.Name = "RareSpins"
RareSpins.Value = SpinsData["RareSpins"]
RareSpins.Parent = Statistics
RareSpins.Changed:Connect(function()
RareSpinStore:Set(RareSpins.Value)
end)
local TraitSpins = Instance.new("IntValue")
TraitSpins.Name = "TraitSpins"
TraitSpins.Value = SpinsData["TraitSpins"]
TraitSpins.Parent = Statistics
TraitSpins.Changed:Connect(function()
TraitSpinsStore:Set(TraitSpins.Value)
end)
end)
---------------------------------------------------------------------
spawn(function()
local CoreData = DataStoreCore("CoreData1", player):Get(CoreTable)
local QuirkStore = DataStoreCore("Quirk", player)
local TraitStore = DataStoreCore("Trait", player)
local StoredPowerStore = DataStoreCore("StoredPower", player)
for i, v in pairs(CoreTable) do
local Name = i
if CoreData[Name] == nil then
AddedNew = true
print("AddingNewValue ".."("..Name..")")
DataStoreCore(Name, player):Get(v)
task.wait(WaitTime)
end
end
if AddedNew == true then
CoreData = DataStoreCore("CoreData1", player):Get()
AddedNew = false
end
local Quirk = Instance.new("StringValue")
Quirk.Name = "Quirk"
Quirk.Value = CoreData["Quirk"]
Quirk.Parent = Statistics
Quirk.Changed:Connect(function()
QuirkStore:Set(Quirk.Value)
end)
local StoredPower = Instance.new("StringValue")
StoredPower.Name = "StoredPower"
StoredPower.Value = CoreData["StoredPower"]
StoredPower.Parent = Statistics
StoredPower.Changed:Connect(function()
StoredPowerStore:Set(StoredPower.Value)
end)
local Trait = Instance.new("StringValue")
Trait.Name = "Trait"
Trait.Value = CoreData["Trait"]
Trait.Parent = Statistics
Trait.Changed:Connect(function()
TraitStore:Set(Trait.Value)
end)
end)
end)