You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
So basically i have datastore with 13 results of data. 12 works fine, but last one works glitchy for some reason. It just do not save data. It always gave me a zero, i checked fifteen times everything, every line , but didn’t figure a reason. So to remove a zero(bcz i use that value to multiply an other value) i made a
rcmulticlicks.Value = result[11] or 1
but it just always give me 1, that means data is nothing. I do not get any error with my prints(bcz when i have error, my game prints what something wrong with data)
2. What is the issue? Include screenshots / videos if possible!
1st
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i checked all my code many times, tryed to find any script which sets value to zero, but when i added
or 1
value become 1
My code:
local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")
local protectedCall = pcall
local function onPlayerJoined(player)
local StatsFolder = Instance.new("Folder")
StatsFolder.Name = "Stats"
StatsFolder.Parent = player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local clicks = Instance.new("IntValue")
clicks.Name = "Clicks"
clicks.Parent = leaderstats
local money = Instance.new("NumberValue")
money.Name = "Money"
money.Parent = leaderstats
local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
local memory = Instance.new("IntValue")
memory.Name = "Memory"
memory.Parent = StatsFolder
local memorylevel = Instance.new("IntValue")
memorylevel.Name = "MemoryLevel"
memorylevel.Parent = StatsFolder
local mouselevel = Instance.new("IntValue")
mouselevel.Name = "MouseLevel"
mouselevel.Parent = StatsFolder
local rcamount = Instance.new("IntValue")
rcamount.Name = "RCAmount"
rcamount.Parent = StatsFolder
local rcmultimoney = Instance.new("NumberValue")
rcmultimoney.Name = "RCMultiMoney"
rcmultimoney.Parent = StatsFolder
local rcmulticlicks = Instance.new("NumberValue")
rcmulticlicks.Name = "RCMultiClicks"
rcmulticlicks.Parent = StatsFolder
local rc1collected = Instance.new("BoolValue")
rc1collected.Name = "RC1Col"
rc1collected.Parent = StatsFolder
local rc2collected = Instance.new("BoolValue")
rc2collected.Name = "RC2Col"
rc2collected.Parent = StatsFolder
local moneyfromtrade = Instance.new("NumberValue")
moneyfromtrade.Name = "MoneyFT"
moneyfromtrade.Parent = StatsFolder
local clicksperclick = Instance.new("NumberValue")
clicksperclick.Name = "ClicksPerClick"
clicksperclick.Parent = StatsFolder
local success, result = protectedCall(function()
return dataStore:GetAsync("Data_"..player.UserId)
end)
if success then
if result then
if type(result) == "table" then
clicks.Value = result[1]
money.Value = result[2]
rebirths.Value = result[3]
memory.Value = result[4]
memorylevel.Value = result[5]
mouselevel.Value = result[6]
rcamount.Value = result[7]
rcmultimoney.Value = result[8]
rc1collected.Value = result[9]
moneyfromtrade.Value = result[10]
rcmulticlicks.Value = result[11] or 1
clicksperclick.Value = result[12]
rc1collected.Value = result[13]
end
end
else
warn(result)
end
end
local function onPlayerLeft(player)
local success, result = protectedCall(function()
return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RCMultiClicks.Value, player.Stats.RC1Col.Value, player.Stats.RC2Col.Value, player.Stats.MoneyFT.Value, player.Stats.ClicksPerClick.Value})
end)
if success then
print(result)
print("Everything success")
else
warn(result)
warn("everything wrong")
end
end
local function onServerClosed()
for _, player in ipairs(playersService:GetPlayers()) do
local success, result = protectedCall(function()
return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RCMultiClicks.Value, player.Stats.RC1Col.Value, player.Stats.RC2Col.Value, player.Stats.MoneyFT.Value, player.Stats.ClicksPerClick.Value})
end)
if success then
print(result)
else
warn(result)
end
end
end
playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed)