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

Why won't this datastore give new players 100 Credits?

Asked by 8 years ago
local DataStore = game:GetService("DataStoreService"):GetGlobalDataStore("TrustCurrency")


game.Players.PlayerAdded:connect(function(plr)

    local bank = game.StarterGui.ScreenGui.Frame.Credits

    local stats = Instance.new("IntValue", plr)
    stats.Name = "leaderstats"

    local credits = Instance.new("IntValue", stats)
    credits.Name = "Credits"

    local key = "player-"..plr.userId

    local savedCredits = DataStore:GetAsync(key)

    if savedCredits == nil then
        local creditcount = (credits.Value + 100)
        DataStore:SetAsync(key, creditcount)
    else
        credits.Value = savedCredits
    end
end)

1 answer

Log in to vote
1
Answered by
thePyxi 179
8 years ago
Edited 8 years ago
local DataStore = game:GetService("DataStoreService"):GetGlobalDataStore("TrustCurrency")
local Repeats = game:GetService("DataStoreService"):GetGlobalDataStore("BeenThere")

game.Players.PlayerAdded:connect(function(plr)
    local inst = Instance.new("StringValue", plr)
    inst.Name = "Repeat"
    inst.Value  = "No"

    local bank = game.StarterGui.ScreenGui.Frame.Credits

    local stats = Instance.new("IntValue", plr)
    stats.Name = "leaderstats"

    local credits = Instance.new("IntValue", stats)
    credits.Name = "Credits"
    credits.Value = 0

    local key = "player-"..plr.userId

    local savedCredits = DataStore:GetAsync(key)
    local savedValue = Repeats:GetAsync(key)

    if savedValue == "No" then
        local creditcount = (credits.Value + 100)
        DataStore:SetAsync(key, creditcount)
        inst.Value = "Yes"
        Repeats:SetAsync(key, inst.Value)
    elseif savedValue == "Yes" then
        credits.Value = savedCredits
        print(savedValue)
    end
end)

Ad

Answer this question