so i am trying to make a BSS fangame, however my datastores clash with eachother.
by that i mean that well, they cant tell eachother apart, and cause overwriting others’ data.
my code:
local Players = game:GetService("Players")
local DatastoreService = game:GetService("DataStoreService")
local database = DatastoreService:GetDataStore("data15")
local sessionData = {}
function PlayerAdded(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local honey = Instance.new("IntValue")
honey.Name = "Honey"
honey.Parent = leaderstats
local tool = Instance.new("NumberValue")
tool.Name = "Tool"
tool.Parent = player
local pollen = Instance.new("IntValue")
pollen.Name = "Pollen"
pollen.Parent = leaderstats
local digrate = Instance.new("NumberValue")
digrate.Name = "Dig Rate"
digrate.Parent = player
local digspeed = Instance.new("NumberValue")
digspeed.Name = "Dig Speed"
digspeed.Parent = player
local wpolmul = Instance.new("NumberValue")
wpolmul.Name = "White Pollen Multiplier"
wpolmul.Parent = player
local rpolmul = Instance.new("NumberValue")
rpolmul.Name = "Red Pollen Multiplier"
rpolmul.Parent = player
local bpolmul = Instance.new("NumberValue")
bpolmul.Name = "Blue Pollen Multiplier"
bpolmul.Parent = player
local newbie = Instance.new("ObjectValue")
newbie.Name = "New Bie"
newbie.Value = nil
newbie.Parent = player
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return database:GetAsync(player.UserId)
end)
attempt += 1
if not success then
warn(playerData)
task.wait(3)
end
until success or attempt == 10
if success then
print("Connected to database")
if not playerData then
print("Assigning default data")
playerData = {
["Honey"] = 0,
["DigRate"] = 0.1,
["DigSpeed"] = 4,
["WPolMul"] = 1,
["RPolMul"] = 1,
["BPolMul"] = 1,
["Tool"] = 1,
["Hive"] = {"Basic Bee"},
}
end
sessionData[player.UserId] = playerData
newbie.Changed:Connect(function()
table.insert(playerData.Hive, newbie.Value.Name)
game.ReplicatedStorage.LoadBees:FireClient(player, playerData.Hive)
newbie.Value = nil
end)
honey.Value = playerData.Honey
honey.Changed:Connect(function()
playerData.Honey = honey.Value
end)
digrate.Value = playerData.DigRate
digrate.Changed:Connect(function()
playerData.DigRate = digrate.Value
end)
tool.Value = playerData.Tool
tool.Changed:Connect(function()
playerData.Tool = tool.Value
end)
digspeed.Value = playerData.DigSpeed
digspeed.Changed:Connect(function()
playerData.DigSpeed = digspeed.Value
end)
wpolmul.Value = playerData.WPolMul
wpolmul.Changed:Connect(function()
playerData.WPolMul = wpolmul.Value
end)
rpolmul.Value = playerData.RPolMul
wpolmul.Changed:Connect(function()
playerData.RPolMul = rpolmul.Value
end)
bpolmul.Value = playerData.BPolMul
wpolmul.Changed:Connect(function()
playerData.BPolMul = bpolmul.Value
end)
print(playerData.Hive)
game.ReplicatedStorage.LoadBees:FireClient(player, playerData.Hive)
game.ReplicatedStorage.GiftBees.OnServerEvent:Connect(function(Player)
game.ReplicatedStorage.ClaimBees:FireClient(player, playerData.Hive)
end)
else
warn("Unable to get data for", player.Name)
player:Kick("Unable to load data, please rejoin if you can")
end
leaderstats.Parent = player
end
Players.PlayerAdded:Connect(PlayerAdded)
function PlayerLeaving(player)
if sessionData[player.UserId] then
local success = nil
local errorMsg = nil
local attempt = 1
repeat
success, errorMsg = pcall(function()
database:SetAsync(player.UserId, sessionData[player.UserId])
end)
attempt += 1
if not success then
warn(errorMsg)
task.wait(3)
end
until success or attempt == 10
if success then
print("Data saved for", player.Name)
else
warn("Unable to save for", player.Name)
end
end
end
Players.PlayerRemoving:Connect(PlayerLeaving)