I’m trying to load data but I’m unsure on how to make it so it can handle more than 1 person joining, this is what happens when more people join
When others that join get the usual amount,
But some get too little
How do I fix this? This is my current script,
local DataWipe = 1
local DataStoreService = game:GetService("DataStoreService")
--local QuestData = DataStoreService:GetDataStore("QuestData"..DataWipe)
local ArmorData = DataStoreService:GetDataStore("Armor"..DataWipe)
local NameData = DataStoreService:GetDataStore("NameNamey"..DataWipe)
local RaceData = DataStoreService:GetDataStore("RaceData"..DataWipe)
local function LoadData(player,character)
local Loading
if not player:FindFirstChild("Data") then
while Loading == true do
wait()
if Loading == false then
break
end
end
Loading = true
local player = player
local character = character
coroutine.wrap(function()
Folder = Instance.new("Folder",player)
Folder.Name = "Data"
Race = Instance.new("StringValue",Folder)
Race.Name = "Race"
Race.Value = RaceData:GetAsync(player.UserId) or "Random"
Namer = Instance.new("StringValue",Folder)
Namer.Name = "Namer"
Namer.Value = NameData:GetAsync(player.UserId) or "Random"
Armor = Instance.new("StringValue",Folder)
Armor.Name = "Armor"
Armor.Value = ArmorData:GetAsync(player.UserId) or "Random"
wait(1)
Loading = false
end)()
else
end
end
game.Players.PlayerAdded:Connect(function(player)
wait(1)
warn("Player Loaded")
local Character = player.Character or player.CharacterAdded:Wait()
repeat wait() until Character
print(Character.Name.." Has just joined. Loading Data!")
LoadData(player,Character)
end)
local DataStoreService = game:GetService("DataStoreService")
local ArmorData = DataStoreService:GetDataStore("Armor"..DataWipe)
local NameData = DataStoreService:GetDataStore("NameNamey"..DataWipe)
local RaceData = DataStoreService:GetDataStore("RaceData"..DataWipe)
This fetches data from the same data store instance for all players.
The reason why you have issues with receiving and sending data to each player is because the variable DataWipe is set to the same value for all players. In the code, DataWipe is used to create the name of the data store instance. So, all players share the same data and will lead to data to be sent and received to any player since every player’s data is connected/shared
Use the UserID of the player to the name of each data store instance, so that each player has their own unique data store instance.
local DataStoreService = game:GetService("DataStoreService")
local playerId = nil
local function LoadData(player, character)
local Loading
if not player:FindFirstChild("Data") then
while Loading == true do
wait()
if Loading == false then
break
end
end
Loading = true
playerId = player.UserId
coroutine.wrap(function()
local Folder = Instance.new("Folder", player)
Folder.Name = "Data"
local Race = Instance.new("StringValue", Folder)
Race.Name = "Race"
Race.Value = RaceData:GetAsync("RaceData_" .. playerId) or "Random"
local Namer = Instance.new("StringValue", Folder)
Namer.Name = "Namer"
Namer.Value = NameData:GetAsync("NameNamey_" .. playerId) or "Random"
local Armor = Instance.new("StringValue", Folder)
Armor.Name = "Armor"
Armor.Value = ArmorData:GetAsync("Armor_" .. playerId) or "Random"
wait(1)
Loading = false
end)()
else
end
end
game.Players.PlayerAdded:Connect(function(player)
wait(1)
warn("Player Loaded")
local Character = player.Character or player.CharacterAdded:Wait()
repeat wait() until Character
print(Character.Name.." Has just joined. Loading Data!")
LoadData(player, Character)
end)