What is the most practical way to store/write shared data?

I want to have the data for my skills accessible by the client and server to help with responsiveness for example when the player does an input I can have the client instantly display the cooldown timer instead of waiting for the server to verify everything and send back the time.

So I’m trying to find out what the most practical way to do this is. I’ve considered just doing a table and having a function to get a specific skill from it so it doesn’t return every skill when I only need 1.

local testHeroSkillData = {
	Skill1 = {
		Damage = 0,
		Cooldown = 10,
		AttackTime = 1.5,
	},
	Skill2 = {
		Damage = 0,
		Cooldown = 3,
		AttackTime = .5,
	}
	--etc
}

return testHeroSkillData

But I feel like I do better than using tables like that so I decided to do this function approach which I think is a bit more flexible.

local testHeroSkillData = {}

function testHeroSkillData.Skill1(check)
	local data = {}
	data.damage = 0
	data.cooldown = 0
	data.attackTime = 0
	
	if check then
		return data
	end

	-- continue with code
end

return testHeroSkillData

And then recently I added OPP so I could do something like this

function testHeroSkillData.new()
	local self = {}
	
	function self.Skill1()
		local data = {}
		
		data.cooldown = 0
		data.attackTime = 0
		data.damage = 0
		
		return data
	end

	return self
end

return testHeroSkillData
function serverTestHero.new()
	local self = testHeroSkillData.new()
	
	local baseSkill1 = self.Skill1
	function self.Skill1()
		local data = baseSkill1()
	end

	return self
end

Although all these approaches work I’m not sure which one is the most practical (if any) to use I have a feeling the OOP one is unnecessary though.

I will show you how to script datastores.
I’ve been working on scripting data for the past 3 months.

Don’t delete one of your scripts.
Firstly add this:
local DSS = game:GetService('DataStoreService')
local DataStore = DSS:GetDataStore("YourDataStoreNameHere") --- I highly suggest not to change it after as it you could lose data.

Edit: Nevermind, I’ll send you the full script.

I’m not trying to save player data in any way so datastores are not needed here lol.

This is just hard coded data/info necessary for the game to function.

Edit: appreciate the effort though :slight_smile:

The problem with your code is that you have not defined the return type of the function testHeroSkillData.Skill1() and the function serverTestHero.new(). Without a return type, the functions will not return anything and will not be able to be used.

To fix this, add the return type for both functions and make sure that each returns the appropriate data type. For example, for the testHeroSkillData.Skill1() function, you should return the data table with all the skill details, like this:

function testHeroSkillData.Skill1(check)
	local data = {}
	data.damage = 0
	data.cooldown = 0
	data.attackTime = 0
	
	if check then
		return data
	end

	return data
end

And for the serverTestHero.new() function, you should also return the data table like this:

function serverTestHero.new()
	local self = testHeroSkillData.new()
	
	local baseSkill1 = self.Skill1
	function self.Skill1()
		local data = baseSkill1()
		return data
	end

	return self
end

Why would I want to return data if I don’t need it? And inside serverTestHero that function doesn’t need to return anything it’s supposed to just run whatever code is necessary for that skill.

Have a “settings module” for each weapon or user. Then, when the user requires the settings module, it gets just what it needs.