Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

DataStore with no error?

Asked by 10 years ago

I'm trying to fix this datastore script I created but I cant fix it if their is no error. Does anyone know what I'm doing wrong or what I'm missing? How could it be more efficient?

local DataStore1 = Game:GetService("DataStoreService"):GetDataStore("Killed")
local DataStore2 = Game:GetService("DataStoreService"):GetDataStore("Currency")
local DataStore3 = Game:GetService("DataStoreService"):GetDataStore("Level")
local DataStore4 = Game:GetService("DataStoreService"):GetDataStore("Experience")

Game.Players.ChildAdded:connect(function(Player)
repeat wait() until Player:FindFirstChild("leaderstats")
local Storage = Player.leaderstats
    Storage:FindFirstChild("Killed").Value = DataStore1:GetAsync("UserKILLED_"..Player.userId) or 0
    Storage:FindFirstChild("Currency").Value = DataStore2:GetAsync("UserCASH_"..Player.userId) or 0
    Storage:FindFirstChild("Level").Value = DataStore3:GetAsync("UserLEVEL_"..Player.userId) or 0
    Storage:FindFirstChild("Experience").Value = DataStore4:GetAsync("UserEXPERIENCE_"..Player.userId) or 0

    DataStore1:OnUpdate("UserKILLED_"..Player.userId,function(New)
    Storage:FindFirstChild("Killed").Value = New
    end)
    DataStore2:OnUpdate("UserCASH_"..Player.userId,function(New)
    Storage:FindFirstChild("Currency").Value = New
    end)
    DataStore3:OnUpdate("UserLEVEL_"..Player.userId,function(New)
    Storage:FindFirstChild("Level").Value = New
    end)
    DataStore4:OnUpdate("UserEXPERIENCE_"..Player.userId,function(New)
    Storage:FindFirstChild("Experience").Value = New
    end)
    DataStore1:UpdateAsync("UserKILLED_"..Player.userId,function(Current)
    local Base1 = Current or 0
    return Base1
    end)
    DataStore2:UpdateAsync("UserCASH_"..Player.userId,function(Current)
    local Base2 = Current or 0
    return Base2
    end)
    DataStore3:UpdateAsync("UserLEVEL_"..Player.userId,function(Current)
    local Base3 = Current or 0
    return Base3
    end)
    DataStore4:UpdateAsync("UserEXPERIENCE_"..Player.userId,function(Current)
    local Base4 = Current or 0
    return Base4
    end)
end)

Answer this question