This datastore is supposed to give new players 100 Credits when they join for the first time. Otherwise pull up their previous balance. Output Below!
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 = plr.PlayerGui.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
bank.Text = credits.Value
end)
Server Output:
23:02:37.789 - Replication: Can't create default object of type Players
23:02:38.750 - ScreenGui is not a valid member of PlayerGui
23:02:38.760 - Script 'ServerScriptService.CurrencyDataStore', Line 9
23:02:38.763 - Stack End
Player -1 added
Shouldn't "plr.PlayerGui.ScreenGui" be correct since 'plr' is the local player? What is the Replication error about? What is wrong with line 9?
(I had help with this once...now it is changed and giving me trouble!)

1 comment
If Filtering Enabled is one, scripts can't access PlayerGui, and you would need to use a Local Script or Remote Events.