Is it necessary to check the datatypes of each variables sent from the client

My intended goal is to stop the script from erroring if the client uses exploits or something to send weird data.

Remotes:WaitForChild("createParty").OnServerEvent:Connect(function(owner, name, access, password, level)
	if type(name) ~= "string" then
			name = ""
		end
		if type(access) ~= "string" then
			access = "Public"
		end
		if type("password") ~= "string" then
			password = ""
		end
-- ect

Is code like this necessary or is there a better way? How do you prevent false data?

It really depends, if there is a vulnerability in your code that can cause errors and make your code not work in the intended way, then yes. but all in all, I would do it anyway.

1 Like

You can’t really prevent false inputs from the client, and whether or not you should type-check changes on a case-by-case basis, so just do it whenever you feel like you should.
A lot of the time, I’ll just let server scripts error: it closes out the code nicely at the very least

I only type-check it if it’s a crucial system where getting another data type could completely brick it (data storage, for example) or if the received variables are being relayed to other clients.

if it helps any then you can have a shorthand with luau by doing in-line conditions

Remotes:WaitForChild("createParty").OnServerEvent:Connect(function(owner, name)
	name = (type(name) == "string" and name) or "default name"
end)

there’s probably a better way of doing it than this but it works for me ^

2 Likes

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