This has been happening for a while but, it seems that the script I made doesn't always save peoples stats in my game, and I'm worried as I am starting to be threatened with people saying they will make Alts and spam dislike my game if I don't do anything about it. This is the code for one of the stats (There are 4 of them, which are all identical besides that they are "KiData", "AgilityData" and "MasteryData"):
local module = {}
local Storage = game:GetService("DataStoreService"):GetDataStore("StrengthData")
game.Players.PlayerAdded:connect(function(plr)
local StrengthData = Instance.new("StringValue", plr)
StrengthData.Name = "StrengthData"
local Strength = Instance.new("NumberValue", StrengthData)
Strength.Name = "Strength"
Strength.Value = math.random(1,300)
local SavedStats = Storage:GetAsync(plr.userId .. "-Strength")
if SavedStats ~= nil then
Strength.Value = SavedStats
end
while true do
wait(0.1)
if StrengthData.Strength.Value > 1000000000000000000 then
StrengthData.Strength.Value = 1000000000000000000
end
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local id = plr.userId
local StrengthValue = plr.StrengthData.Strength.Value
Storage:SetAsync(id.. "-Strength", StrengthValue)
end)
return module
The script resides in the ServerScriptService, and is a Module Script inside a normal script in the ServerScriptService which only has one line of code:
require(script:WaitForChild("ModuleScript"))
So could somebody please tell me what isn't working here? If there is a fix to stop people losing stats from my game, that would be very helpful if you manage to find it, thank you.
