Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is this remote secure enough?

local RS = game:GetService("ReplicatedStorage")
local BuyItem = RS.Events.BuyItem
local ServerStorage = game:GetService("ServerStorage")


--In a Table--
local shopItems = {
    ClassicSword = {
        Tool = game.ServerStorage.Items.ClassicSword,
        Price = 500
    },
	
	RainbowMagicCarpet = {
		Tool = game.ServerStorage.Items.RainbowMagicCarpet,
		Price = 2000		
	},
}
	

--BuyItem
BuyItem.OnServerEvent:Connect(function(player,item)
	local backpack = player:WaitForChild("Backpack")
	
	if shopItems[item] and backpack then
		if
			player.Money.Value >=shopItems[item].Price then
			shopItems[item].Tool:Clone().Parent = backpack
			player.Money.Value = player.Money.Value -shopItems[item].Price
			print("Purchased Item!")
		else
			print("Purchase failed!")
		end
	end
end)

So I just started learning remote events and stuff, anyways, I've been working on this BuyItem remote and I'm wondering if this is safe enough to stop most exploiters or do I need to add more security?

1 comment

0

A way I like to check is by trying to exploit it using a localscript.

1 answer

✓ Accepted answer

Remember it's possible for hackers to fire or invoke your remotes through injected code, passing whatever arguments they want as input. So you must make sure the arguments received match the types you are expecting.

For example, a hacker could fire your remote with a nil value as argument, which would cause your if shopItems[item] ... then check to break with a "Table index is nil" error message.

Another example would be a RemoteEvent used to withdraw money from a bank:

Withdraw.OnServerEvent:Connect(function(player, amount)
	if player.BankBalance.Value >= amount then
		player.WalletBalance.Value = player.WalletBalance.Value + amount
	end
end)

in this case the >= check may error, as the greater-than-or-equal-to comparison may not be defined for the type of value received as argument.

A good idea, although it quickly makes remote communications code unreadable, is to add

if typeof(arg) == "expectedType" then return end

checks at the beginning of your functions.

Note that typeof(x) will return the Roblox type of the argument value, so a Vector3 value will result in the string "Vector3" being returned, whereas type(x) would only return the Lua type of the argument, which is `"userdata".

Note also that for Instance values, typeof(x) will only return the string "Instance", not the class of the Instance. For this you should use instance:IsA("Class") or instance.ClassName == "Class".

Otherwise, everything looks fine. :)

2 comments

1

Its "exploiter" not hacker

0

It is a hacker. An "exploiter" would simply mean someone who exploits a flaw in the game, not necessarily using third party software.

This discussion is preserved as it was. New answers, comments, and votes are closed.