My Datastore won't save. This is causing issues between The game and the avatar creator. If the player has not created an avatar, it will send them to the creator. Once created, a value is ticked. It is not saving, so it is just an endless loop between teleporting to both of the places.
Yes, the game does have access to the datastore service as I have checked the little box.
local Datastore = game:GetService("DataStoreService"):GetDataStore("Seraph1V5!")
local ServerStorage = game:GetService("ServerStorage")
local Noob = {
Seraph = false,
Tries = 3,
Race = "Human",
Hair = "Beautiful Hair",
Shirt = "Yu",
Pants = "Yu",
Colour = "Pastel Brown",
LuckyNumber = 0,
CharacterCreated = false,
}
PlayerAdded = function(player)
local key = "user "..player.UserId
local Persistance = Instance.new("Folder", ServerStorage)
Persistance.Name = "Persistance"..player.Name
local Data = Instance.new("Folder", Persistance)
Data.Name = "Data"
local Seraph = Instance.new("BoolValue", Data)
Seraph.Name = "Seraph"
local Tries = Instance.new("IntValue", Data)
Tries.Name = "Tries"
local Race = Instance.new("StringValue", Data)
Race.Name = "Race"
local Hair = Instance.new("StringValue", Data)
Hair.Name = "Hair"
local Shirt = Instance.new("StringValue", Data)
Shirt.Name = "Shirt"
local Pants = Instance.new("StringValue", Data)
Pants.Name = "Pants"
local Colour = Instance.new("StringValue", Data)
Colour.Name = "Colour"
local LuckyNumber = Instance.new("StringValue", Data)
LuckyNumber.Name = "LuckyNumber"
local CharacterCreated = Instance.new("BoolValue", Data)
CharacterCreated.Name = "CharacterCreated"
local StoredData = Datastore:GetAsync(key) or Noob
Seraph.Value = StoredData.Seraph
Tries.Value = StoredData.Tries
Race.Value = StoredData.Race
Hair.Value = StoredData.Hair
Shirt.Value = StoredData.Shirt
Pants.Value = StoredData.Pants
Colour.Value = StoredData.Colour
LuckyNumber.Value = StoredData.LuckyNumber
CharacterCreated.Value = StoredData.CharacterCreated
end
-----------------------------------------------------------
PlayerLeaving = function(player)
local key = "user "..player.UserId
local success, message = pcall(function()
Datastore:SetAsync(key, {
Seraph = ServerStorage["Persistance"..player.Name.Data.Seraph.Value],
Tries = ServerStorage["Persistance"..player.Name.Data.Tries.Value],
Race = ServerStorage["Persistance"..player.Name.Data.Race.Value],
Hair = ServerStorage["Persistance"..player.Name.Data.Hair.Value],
Shirt = ServerStorage["Persistance"..player.Name.Data.Shirt.Value],
Pants = ServerStorage["Persistance"..player.Name.Data.Pants.Value],
Colour = ServerStorage["Persistance"..player.Name.Data.Colour.Value],
LuckyNumber = ServerStorage["Persistance"..player.Name.Data.LuckyNumber.Value],
CharacterCreated = ServerStorage["Persistance"..player.Name.Data.CharacterCreated.Value]
})
end)
if success then
print("Saved '"..player.Name.."' Data. " .. message)
end
end
game.Players.ChildAdded:Connect(function(player) PlayerAdded(player) end)
game.Players.ChildRemoved:Connect(function(player) PlayerLeaving(player) end)
--------------------------------------------------------------------------------

2 comments
game.Players.PlayerAdded and PlayerRemoved
Don't forget to accept my answer if it helps