-
What do you want to achieve? I want to get the TowerData from the player in the universal place however it doesn’t get it.
-
What is the issue? It doesn’t get the tower data from the player from the universal place.
-
What solutions have you tried so far? Found none relating to this topic at all.
Lobby Place Data Code:
local PlayerDataModule = {}
PlayerDataModule.ServerStorage = game:GetService("ServerStorage")
PlayerDataModule.DataStore2 = require(script.DataStore2)
function PlayerDataModule.StoreData(Player)
local NewTowerData = {}
local NewCashValue = Player.leaderstats.Cash.Value
local NewTokenValue = Player.leaderstats.Tokens.Value
for _, TowerValue in pairs(PlayerDataModule.ServerStorage[Player.Name.."'s TowerPurchaseData"]:GetChildren()) do
table.insert(NewTowerData, TowerValue.Name)
print(TowerValue.Name)
end
local PlayerDataStore = PlayerDataModule.DataStore2("PlayerData", Player)
PlayerDataStore:Update(function(PlayerData)
local NewPlayerData = PlayerData
NewPlayerData.TowerData = NewTowerData
NewPlayerData.Cash = NewCashValue
NewPlayerData.Tokens = NewTokenValue
return NewPlayerData
end)
end
function PlayerDataModule.LoadData(Player)
local PlayerDataStore = PlayerDataModule.DataStore2("PlayerData", Player)
local PlayerData = PlayerDataStore:GetTable({
TowerData = {},
Cash = 0,
Tokens = 0
})
local TowerDataFolder = Instance.new("Folder")
TowerDataFolder.Name = Player.Name.."'s TowerPurchaseData"
TowerDataFolder.Parent = PlayerDataModule.ServerStorage
local LeaderstatsFolder = Instance.new("Folder")
LeaderstatsFolder.Name = "leaderstats"
LeaderstatsFolder.Parent = Player
local CashIntValue = Instance.new("IntValue")
CashIntValue.Name = "Cash"
CashIntValue.Value = PlayerData.Cash
CashIntValue.Parent = LeaderstatsFolder
local TokenIntValue = Instance.new("IntValue")
TokenIntValue.Name = "Tokens"
TokenIntValue.Value = PlayerData.Tokens
TokenIntValue.Parent = LeaderstatsFolder
if #PlayerData.TowerData > 0 then
for i = 1, #PlayerData.TowerData do
local NewValue = Instance.new("BoolValue")
NewValue.Name = PlayerData.TowerData[i]
NewValue.Parent = TowerDataFolder
print(NewValue.Name)
end
end
TowerDataFolder.ChildAdded:Connect(function(Value)
if table.find(PlayerData.TowerData, Value.Name) then
print(Value.Name, "[Purchased] -", TowerDataFolder.Name)
end
end)
end
return PlayerDataModule
Universal Place Get Data Code:
local PlayerDataModule = {}
PlayerDataModule.DataStore2 = require(script.DataStore2)
function PlayerDataModule.GetData(Player)
local PlayerDataStore = PlayerDataModule.DataStore2("PlayerData", Player)
local PlayerData = PlayerDataStore:GetTable({
TowerData = {},
})
for _, Tower in pairs(PlayerData.TowerData) do
if table.find(PlayerData.TowerData, Tower.Name) then
print(Tower)
end
end
end
return PlayerDataModule
The crucial problem is the get data code however I included the lobby data code to give you an example.
The get data code doesn’t print anything at all. It’s suppose to print the player’s lobby tower data - Aka. BoolValues in it that was inserted into the NewTowerData table in the lobby however it doesn’t print anything.
Am I doing something wrong with the universal place code? Because If this problem doesn’t get resolved my tower defense game would have to rely on no teleportation which kinda sucks.
2 Likes
is a universal place the same place but an universal place and yes i am using datastores (datastore 2 module i just need to get the data thats all)
1 Like
I’m talking about storing/retrieving data from a Datastore, not a module
Do you have anything inside the module accessing Datastores?
Yes, I’m using the DataStore2 module to create and store and retrieve Tower Data from the code however the universal place code is the crucial problem it doesn’t get an table and i need to loop through that table for tower strings.
I will show you updated lobby code.
Can you try printing the data you get and show me?
Also you haven’t answered my question, is the module accessing Datastores or is it stored in the module only?
its stored in the module and accesses datastores.
Can I see what’s in the module?
Sure do you want both code or the lobby code? or the universal one.
I want to see where you’re communicating with Datastores inside the module
Alright. I will give you both in both places than.
1 Like
Lobby Data Module Code
local PlayerDataModule = {}
PlayerDataModule.ServerStorage = game:GetService("ServerStorage")
PlayerDataModule.DataStore2 = require(script.DataStore2)
function PlayerDataModule.StoreData(Player)
local NewTowerData = {}
local NewCashValue = Player.leaderstats.Cash.Value
local NewTokenValue = Player.leaderstats.Tokens.Value
for _, TowerValue in pairs(PlayerDataModule.ServerStorage[Player.Name.."'s TowerPurchaseData"]:GetChildren()) do
table.insert(NewTowerData, TowerValue.Name)
print(TowerValue.Name)
end
local PlayerDataStore = PlayerDataModule.DataStore2("PlayerData", Player)
PlayerDataStore:Update(function(PlayerData)
local NewPlayerData = PlayerData
NewPlayerData.TowerData = NewTowerData
NewPlayerData.Cash = NewCashValue
NewPlayerData.Tokens = NewTokenValue
return NewPlayerData
end)
end
function PlayerDataModule.LoadData(Player)
local PlayerDataStore = PlayerDataModule.DataStore2("PlayerData", Player)
local PlayerData = PlayerDataStore:GetTable({
TowerData = {},
StringData = {},
Cash = 0,
Tokens = 0
})
local TowerDataFolder = Instance.new("Folder")
TowerDataFolder.Name = Player.Name.."'s TowerPurchaseData"
TowerDataFolder.Parent = PlayerDataModule.ServerStorage
local LeaderstatsFolder = Instance.new("Folder")
LeaderstatsFolder.Name = "leaderstats"
LeaderstatsFolder.Parent = Player
local CashIntValue = Instance.new("IntValue")
CashIntValue.Name = "Cash"
CashIntValue.Value = PlayerData.Cash
CashIntValue.Parent = LeaderstatsFolder
local TokenIntValue = Instance.new("IntValue")
TokenIntValue.Name = "Tokens"
TokenIntValue.Value = PlayerData.Tokens
TokenIntValue.Parent = LeaderstatsFolder
if #PlayerData.TowerData > 0 then
for i = 1, #PlayerData.TowerData do
local NewValue = Instance.new("BoolValue")
NewValue.Name = PlayerData.TowerData[i]
NewValue.Parent = TowerDataFolder
print(NewValue.Name)
table.insert(PlayerData.StringData, NewValue.Name)
end
end
TowerDataFolder.ChildAdded:Connect(function(Value)
if table.find(PlayerData.StringData, Value.Name) then
print(Value.Name, "[Purchased] -", TowerDataFolder.Name)
end
end)
end
return PlayerDataModule
Universal Place Code
local PlayerDataModule = {}
PlayerDataModule.DataStore2 = require(script.DataStore2)
local DefaultPlayerData = {
StringData = {},
}
function PlayerDataModule.GetData(Player)
local PlayerDataStore = PlayerDataModule.DataStore2("PlayerData", Player)
print(PlayerDataStore.StringData)
for _, TowerName in pairs(PlayerDataStore:GetTable(DefaultPlayerData).StringData) do
print("Tower:", TowerName)
end
end
return PlayerDataModule
This code doesn’t print anything even tho it’s suppose to get the string data.
1 Like
Apparently you’re not using anything from DataStores. I don’t see that you’re sending data to Roblox anywhere, which would mean you cannot access it from another Place.
In order to access data from another Place, you need DataStoreService
DataStore2 is a popular module that handles DataStore functions on its own. I’m not familiar with it to be honest, it’s really hard to help people when they use other people’s code, but that’s the way of it.
Also how is this urgent? Unless this is a new bug and it used to work properly, in which case I could understand it because your game with tons of players would be suddenly non-functional. But something that never worked in the first place wouldn’t be urgent.
1 Like
It’s because if this problem doesn’t get solved. I would just rely on no teleportation which kinda sucks for my TD game. And I want my game to rely on teleportation.
How would I get StringData from the get data code and loop through it?
Oh I never knew about that lol. If it were me I’d prefer just using DatastoreService