Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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)

This discussion is preserved as it was. New answers, comments, and votes are closed.