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

Data Store for player Data?

Asked by 9 years ago

---Yes this is long, no errors in output, only problem is that "Goldbars" Only saves very rarely, and its a bit of an issue its anoying any help would be loved, coins and such save but not gold. :( Its not local and its in severscriptservice

local DataStoreService = game:GetService("DataStoreService")
game.Players.PlayerAdded:connect(
function(Player)
local PlayerStore = DataStoreService:GetDataStore(tostring(Player.userId), "PlayerData")
-----
print(Player.Name .. ", You've joined " .. PlayerStore:GetAsync("Joins") .. " Times!")
if PlayerStore:GetAsync("Joins") >= 10 then
print"You've visted more then 10 times ;D THANKS!"
end
print((PlayerStore:GetAsync("Coins") or "0") .. " Coins in your bank")
print((PlayerStore:GetAsync("GoldBars") or "0") .. " GoldBars in your bank")
----Start Of Client Store
local DataStore = Instance.new("IntValue")
DataStore.Name = "Data"
DataStore.Parent = Player
------Player load
local coins = Instance.new("NumberValue")
coins.Name = "Coins"
coins.Parent = DataStore
coins.Value = PlayerStore:GetAsync("Coins")
-----
local gold = Instance.new("NumberValue")
gold.Name = "GoldBars"
gold.Parent = DataStore
gold.Value = PlayerStore:GetAsync("GoldBars")
-----
local joined = Instance.new("NumberValue")
joined.Name = "Joins"
joined.Parent = DataStore
joined.Value = PlayerStore:GetAsync("Joins")
-----
Player:WaitForChild("Data")
joined.Value = joined.Value +1
if Player.Data.Joins.Value <2 then
----
print"I see this is your first time playing :D Thanks for playing"
else
print"You've played before, THANKS! :D"
end
------
print("You have " .. (PlayerStore:GetAsync("Coins") or "0") .. " Coins!")
print("You have " .. (PlayerStore:GetAsync("GoldBars") or "0") .. " GoldBars!")
print("You've joined " .. PlayerStore:GetAsync("Joins") .. " Times!")
end
)
-----UpdateAsync
game.Players.PlayerRemoving:connect(function(Player)
local PlayerStore = DataStoreService:GetDataStore(tostring(Player.userId), "PlayerData")
PlayerStore:SetAsync("Coins", Player.Data.Coins.Value)
PlayerStore:SetAsync("Joins", Player.Data.Joins.Value)
PlayerStore:SetAsync("GoldBars", Player.Data.GoldBars.Value)
end)

Answer this question