If I use _G to make a table for all players to store data would that be more secure and prevent stat exploits?

Example:

local DataStore = game:GetService("DataStoreService"):GetDataStore("TEST")
local DataKey = "~~" --..UserId

_G["DataTable"] = {}

local DataTable = _G["DataTable"]

function Join(player)
	local UserId = player.UserId
	local Data = DataStore:GetAsync(DataKey..UserId)
	if Data then
		DataTable[player.UserId] = {}
		DataTable[player.UserId]["Stats"] = {}
		DataTable[player.UserId]["Stats"]["Money"] = Data[1]
	else
		DataTable[player.UserId] = {}
		DataTable[player.UserId]["Stats"] = {}
		DataTable[player.UserId]["Stats"]["Money"] = 2500
		DataStore:SetAsync(DataKey..UserId,{DataTable[player.UserId]["Stats"]["Money"]})
	end
end

function Leave(player)
	local UserId = player.UserId
	local PDataTable = DataTable[UserId]
	local Stats = PDataTable["Stats"]
	local Money = Stats["Money"]
	local Table = {Money}
	DataStore:SetAsync(DataKey..UserId,Table)
end

game.Players.PlayerAdded:Connect(Join)
game.Players.PlayerRemoving:Connect(Leave)

I would think it would be more secure seeing what _G is in the wiki.

3 comments

1

No. don't use _G

1

Don't let the client have control of anything about the stats. Then it will be secure, that's all you need is to not trust the client to make it secure. if a client changes their stats locally it won't replicate to the server and it will see it as their old amount before exploiting.

0

^What he said