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

2nd and 3rd leaderstats are not saving but 1st will, and gamepass isnt one-time?

Asked by 3 years ago

leaderstats:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("officialpointfortlolSaveSystem")
local ds2 = datastore:GetDataStore("changetheimagecoinsSaveSystem")
local ds3 = datastore:GetDataStore("ctirebirthsSaveSystem")

local gamepass_id1 = 18287787
local gamepass_id2 = 18287797
local gamepass_id3 = 18309443
local stat = "Changes"
local gamepass_stat1 = 100
local gamepass_stat2 = 1000
local gamepass_stat3 = 10000


game.Players.PlayerAdded:connect(function(plr)
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local gems = Instance.new("IntValue", folder)
    gems.Name = "Changes"
    local coins = Instance.new("IntValue", folder)
    coins.Name = "Coins"
    local rebirths = Instance.new("IntValue", folder)
    rebirths.Name = "Rebirths"

    gems.Value = ds1:GetAsync(plr.UserId) or 0
    ds1:SetAsync(plr.UserId, gems.Value)

    gems.Changed:connect(function()
        ds1:SetAsync(plr.UserId, gems.Value)

    coins.Value = ds2:GetAsync(plr.UserId) or 0
        ds2:SetAsync(plr.UserId, coins.Value)

    coins.Changed:connect(function()
            ds2:SetAsync(plr.UserId, coins.Value)

    rebirths.Value = ds3:GetAsync(plr.UserId) or 0
            ds3:SetAsync(plr.UserId, rebirths.Value)

    rebirths.Changed:connect(function()
            ds3:SetAsync(plr.UserId, rebirths.Value)        

    local award3 = Instance.new("BoolValue", plr)
    award3.Name = "Award3"

        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamepass_id3) and plr.Award3.Value == false then 
            plr.Award3.Value = true
            gems.Value = gems.Value + gamepass_stat3
        end
    end)
end)

while wait(3) do
    for i, v in pairs(game.Players:GetChildren()) do
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(v.UserId, gamepass_id3) and v:WaitForChild("Award3").Value == false then
            v.Award3.Value = true
            v.leaderstats:FindFirstChild(stat).Value = v.leaderstats:FindFirstChild(stat).Value + gamepass_stat3            
        end
    end
end

game.ReplicatedStorage.re.OnServerEvent:Connect(
    function(player)
        player.leaderstats.Changes.Value += 1
            end)
        end)
    end)

gems will save but coins and rebirths will not. how to solve??

and im making a gamepass for 10,000 gems that works, but wont stop giving it to me everytime i rejoin, how to make it only do once forever?

Answer this question