Feedback on my DataStore script

I made a data store code for the game, you guys think this enough good ?

DataStore = game:GetService("DataStoreService")
PlayerStats = DataStore:GetDataStore("PlayerData")

    local StarterStats = {
    	Power = 0;
    	Test = 0;
    }

    local StarterSkill = {
    	Skill1 = "";
    	Skill2 = "";
    	Skill3 = "";
    	Skill4 = "";
    	Skill5 = "";
    	Skill6 = "";
    	Skill7 = "";
    	SkillR = "";
    	SkillT = "";
    }

    function GetTable(folder)
    	local tableV = {};
    	for _, stat in pairs(folder:GetChildren()) do
    		tableV[stat.Name] = stat.Value;
    	end 
    	return tableV
    end
    local function CreateStarter(plr)
    	local folder = Instance.new("Folder",plr)
    	folder.Name = "Stats"
    	for name,val in pairs(StarterStats) do
    		local valtype = typeof(val)
    		if valtype == "string" then
    			local instance = Instance.new("StringValue",folder)
    			instance.Name = name
    			instance.Value = val
    		elseif valtype == "number" then
    			local instance = Instance.new("NumberValue",folder)
    			instance.Name = name
    			instance.Value = val
    		elseif valtype == "boolean" then
    			local instance = Instance.new("BoolValue",folder)
    			instance.Name = name
    			instance.Value = val
    		end
    	end
    end

    local function CreateSkills(plr)
    	local folder = Instance.new("Folder",plr)
    	folder.Name = "Skills"
    	for name,val in pairs(StarterSkill) do
    		local instance = Instance.new("StringValue",folder)
    		instance.Name = name
    		instance.Value = val
    	end
    end

    local function CreateValues(folder,dataTable)
    	for name,val in pairs(dataTable) do
    		local valtype = typeof(val)
    		if valtype == "string" then
    			local instance = Instance.new("StringValue",folder)
    			instance.Name = name
    			instance.Value = val
    		elseif valtype == "number" then
    			local instance = Instance.new("NumberValue",folder)
    			instance.Name = name
    			instance.Value = val
    		elseif valtype == "boolean" then
    			local instance = Instance.new("BoolValue",folder)
    			instance.Name = name
    			instance.Value = val
    		end
    	end
    	print(folder.Name)
    end

    local function createAnotherFolder(plr)
    	local folder = Instance.new("Folder",plr)
    	folder.Name = "MeleeSkills"
    	local folder = Instance.new("Folder",plr)
    	folder.Name = "KiSkills"
    	local folder = Instance.new("Folder",plr)
    	folder.Name = "Transformatios"
    end

    local function CreateData(plr)
    	local stat = {};
    	local table1 = GetTable(plr.Stats)
    	local table2 = GetTable(plr.Skills)
    	local table3 = GetTable(plr.MeleeSkills)
    	local table4 = GetTable(plr.KiSkills)
    	local table5 = GetTable(plr.Transformatios)
    	stat = {table1,table2,table3,table4,table5}
    	local Succes,Error = pcall(function()
    		PlayerStats:GetAsync(plr.UserId)
    	end)
    	if Succes then
    		print("data loaded :3")
    	else
    		PlayerStats:SetAsync(plr.UserId,stat)
    	end
    end

    local function LoadData(player)
    	local statData = {};
    	
    	local Succes,Error = pcall(function()
    		statData = PlayerStats:GetAsync(player.UserId)
    	end)
    	
    	if statData then
    		print("ı loading your datas")
    		function Loader(folder,dataTable)
    			for name, val in pairs(dataTable) do
    			folder[name].Value = val;
    			end
    			print(folder.Name)
    		end
    		for val,n in pairs(statData) do
    			if val == 1 then
    				Loader(player.Stats,n)
    			elseif val == 2 then
    				Loader(player.Skills,n)
    			elseif val == 3 then
    				CreateValues(player.MeleeSkills,n)
    			elseif val == 4 then
    				CreateValues(player.KiSkills,n)
    			elseif val == 5 then
    				CreateValues(player.Transformatios,n)
    			end
    		end	
    		print("data load completed for "..player.Name)
    	else
    		print("New Data for ".. player.Name.. " :^3");
    		CreateData(player)
    	end
    end

    local function NewDataSave(player)--data saver
    	local stat = {};
    	local table1 = GetTable(player.Stats)
    	local table2 = GetTable(player.Skills)
    	local table3 = GetTable(player.MeleeSkills)
    	local table4 = GetTable(player.KiSkills)
    	local table5 = GetTable(player.Transformatios)
    	stat = {table1,table2,table3,table4,table5}
    	local Succes,Error = pcall(function()
    		PlayerStats:SetAsync(player.UserId,stat)
    	end)
    	if Succes then
    		print("Datas Saved For "..player.Name)
    	else
    		print("Datas Not Saved oof")
    	end
    end

    game.Players.PlayerAdded:Connect(function(plr)
    	CreateStarter(plr)
    	CreateSkills(plr)
    	createAnotherFolder(plr)
    	LoadData(plr)
    end)

    game.Players.PlayerRemoving:Connect(function(plr)
    	NewDataSave(plr)
    end)
2 Likes

Showing your datastore script is a Big no no. Because you just gave hackers complete access to your datastore.

1 Like

He didn’t show which game he’s making.

A hacker can access the datastore without the game

No… not really, exploiters (without a backdoor) cannot do anything with a datastore name, so @ezicirakoYT doesn’t need to worry.

By the way, @ezicirakoYT, you should move this to #help-and-feedback:code-review - this topic is specifically for what you want to do.

As a former exploiter, I can conclude that you’re completely wrong, even in a different game you still cannot access these stores

1 Like

Thanks for the point-out. I’ve recategorised this to Code Review.

Cool Creations should be for showcasing significant assets in action and receiving feedback or comments on them. Code Review would be best for receiving feedback specifically on code because that way you can also get some ideas on how to improve the code.

Code Review threads should be asking for a comprehensive review on what they find may be problematic in a code piece though, so I would encourage reviewing the category guidelines to help touch up the post or anything. Otherwise, feedback for code in Code Review please!

1 Like

actually exploits are basic local script executor they can’t acces datastore
also, i don’t care about my script stolen