Object-Oriented Programming with DataStores?

Assuming that script is a ModuleScript, which it should be, you would have to use the global require function to get the table (PlayerData in your case) returned by the module.

local PlayerData = require(path_to_module)

Then you would be able to create new “objects” of PlayerData for each new player.

Players.PlayerAdded:Connect(function(Player)
  local newPlayerData = PlayerData.new(Player)
end)

Next you can use the “newPlayerData” and call the methods on it:

Players.PlayerAdded:Connect(function(Player)
  local newPlayerData = PlayerData.new(Player)
  newPlayerData:Load()
  -- etc
end)
1 Like