Is this a virus?

Found this script in the toolbox. It saves a list of items and I’m wondering if it is a virus. I have no idea what httpservice does and why they would need it.

script:

local scope = 'Game' --Switch it to 'Game' when you publish it, so saved data from test won't transfer over to the real game

local ss = game:GetService('ReplicatedStorage')
local ps = game:GetService('Players')
local ds = game:GetService('DataStoreService'):GetDataStore('PlayerData',scope)
local hs = game:GetService('HttpService') --What is this??? Virus???????

local dataFolder = ss:WaitForChild('PlayerData')
local storeFolder = dataFolder:WaitForChild('Store') --where each players' folder will be
local defaultFolder = dataFolder:WaitForChild('Default-Data')

local prepareFolder = function(player,data)
	local playerFolder = storeFolder:FindFirstChild(player.Name)
	local newData = hs:JSONDecode(data)
	if not playerFolder then
		local folder = defaultFolder:Clone(); folder.Name = player.Name; folder.Parent = storeFolder
		playerFolder = folder
	end
	for name,value in pairs(newData) do
		local objInDefault = defaultFolder:FindFirstChild(name) --doesn't create a value obj for anything if it doesnt exist in defaultFolder
		if objInDefault then
			playerFolder[name].Value = value
		end
	end
	return playerFolder
end

local savePlayerData = function(player)
	local playerFolder = storeFolder:FindFirstChild(player.Name)
	if not playerFolder then
		local folder = defaultFolder:Clone(); folder.Name = player.Name; folder.Parent = storeFolder
		playerFolder = folder
	end
	local dataList = {}	--Saves it into a list as a key-value pairs, key is the name, value is the objects value
	for i,value in pairs(defaultFolder:GetChildren()) do
		--Since only values with names matching from defaultFolder will be saved, you can put any value you like
		local currentSaving = playerFolder[value.Name] -- value is an instance object
		if not currentSaving then
			local newObj = value:Clone(); newObj.Parent = playerFolder
		end
		dataList[value.Name] = currentSaving.Value
	end
	dataList = hs:JSONEncode(dataList)
	ds:SetAsync(player.userId,dataList)
	return dataList,playerFolder
end

local fetchPlayerData = function(player)
	local newData = ds:GetAsync(player.userId)
	if not newData then
		newData = savePlayerData(player) --saves the data if no previous saves exists and returns it
	end
	local playerFolder = prepareFolder(player,newData)
	return playerFolder
end

ps.PlayerAdded:connect(function(player)
	fetchPlayerData(player)
end)
--Sometimes this connection can't be made for the fircst player (happens mostly in studio)
if ps.NumPlayers >= 1 then
	for i,player in pairs(ps:GetPlayers()) do
		if not storeFolder[player.Name] then
			fetchPlayerData(player)--gets their data if its not in there
		end
	end
end

ps.PlayerRemoving:connect(function(player)
	local _,folder = savePlayerData(player) --we need the second returned value so ignore the first one by using _
	folder:Destroy()
end)
2 Likes

Yes! It’s a virus! Remove it immedietly! This will cause your game to crash instantly!!!

Jokin- Joking… Haha. Sorry!
It’s not a virus. But… I would recommend hiring someone (if you don’t know how to code) or to make this script yourself.

HttpService, in this case, is being used to import the JSONEncode and JSONDecode methods, which (de)serializes user data to and from json format. This is a typical data-saving script, nothing more, nothing less.

HttpService is also typically used to make GET/POST requests to API endpoints, which is not something happening here

2 Likes

So it is? Or is it fine? I’m not familiar with https

1 Like

It’s tottally fine. Just people using HTTPService sometimes for only JSON Encoding and Decoding

2 Likes

Yes, this script is fine, all typical usage here

2 Likes

I do I’m just not familiar with data stores.

There are tutorials and I mean hundreds of them on the internet. All of them teach good in their own ways. It won’t take long for you to learn datastores.

To save player’s data: datastore:SetAsync(userid, value to save)
To load: datastore:GetAsync(userid)

But let’s not forget that OP still needs to use HTTPService:JSONDecode/Encode to save and load the data respectively, because datastores only accept strings.

Learn more →

In the future, I would recommend this plugin. I’ve been using it personally for years.

Game Guard Anti-Virus

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.