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

What is wrong with my Encryption script?

It isn't working, and I don't understand what the Output means. Here is the script;

function Encryptor(Encrypt)
local String = ""
for i = 1,Encrypt:len() do
String = String..string.char(92)..Encrypt:sub(i,i):byte()
end
end

wait(5)

local cl = script.ScriptBase:Clone()
cl.Code.Value = Encryptor([[print("XD")]])
cl.Parent = game.ServerScriptService
cl.Disabled = false

The Output said; 19:07:29.174 - String expected 19:07:29.175 - Script 'ServerScriptService.Script', Line 12 19:07:29.176 - Stack End

1 comment

0

Remember that while this may be a good exercise, as an actual security technique is futile and will not protect your code

2 answers

You're missing one line on the function, the famous return

function Encryptor(Encrypt)
local String = ""
for i = 1,Encrypt:len() do
String = String..string.char(92)..Encrypt:sub(i,i):byte()
end
return String --Or any value you're attempting to return.
end

wait(5)

local cl = script.ScriptBase:Clone()
cl.Code.Value = Encryptor([[print("XD")]])
cl.Parent = game.ServerScriptService
cl.Disabled = false

It should work.

2 comments

0

Thanks, it works! But there is a new error. :/ The Output says 19:44:01.200 - ServerScriptService.ScriptBase:2: attempt to call a nil value 19:44:01.202 - Stack Begin 19:44:01.203 - Script 'ServerScriptService.ScriptBase', Line 2 19:44:01.204 - Stack End, whats that mean?

0

Hmm... That's odd... Could it be because the return is inside the for loop? try moving the return String to in the middle of the two "end"s. That, or I think you actually can't store concatenations in values.

Your function lacks a return, so it evaluates to nil only.

This return must happen after compiling your string.

May I also recommend clearer variable names? Ideally scripts would read fairly naturally outloud. Names like encrypt as the parameter aren't really clear; it should be somethign more like text; we know it is to be encrypted because the function is called Encryptor (although since it is doing something to something, we should probably use the verb, Encrypt)

Also, tabbing is important to code readability!

function Encrypt(Text)
	local EncryptedText = ""
	for i = 1, #Text do
		EncryptedText = EncryptedText .. string.char(92) .. Text:sub(i,i):byte()
	end
	return EncryptedText
end

Remember that any system that just transforms the text like this doesn't actually protect your code if someone gets their hands on all of this: they can just say

loadstring = print

and get everything back.

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