Hello! I’m basically new to loadstrings.
I’m trying to make a command on my admin that goes like the following;
:execute print("Hello")
. I need to use a Remote because everything I do is in a LocalScript. How would I do it?
Hello! I’m basically new to loadstrings.
I’m trying to make a command on my admin that goes like the following;
:execute print("Hello")
. I need to use a Remote because everything I do is in a LocalScript. How would I do it?
You can use string.split for this. Make sure LoadstringEnabled is enabled (in ServerScriptService). It may be risky to have enabled in some cases.
local Players = game:GetService('Players')
local Prefix = ':'
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
local Splits = Message:split(' ')
local String
if Splits[1]:lower() == Prefix .. 'execute' then
if Splits[2] and Splits[2]:find('%w') then
table.remove(Splits, 1) -- Remove the first argument from the table
String = table.concat(Splits, ' ') -- Include everything except the actual command name
loadstring(String)()
end
end
end)
end)
This SHOULD be a server script. You don’t need a localscript.
One thing I would like to say is that enabling loadstring in your game can cause security issues in your game.
(Basically backdoors / viruses can use loadstring to run whatever it wants in your game)
True, but it’s not for a game script or anything. I’m basically making my own ServerSided admin with UTG scripts, it’s really really underrated and people see it as exploiting for some reason but ya know.
You should almost always disable the Lua loadstring() function (it’s disabled by default). This function is both powerful and dangerous because it allows arbitrary and dynamic code to execute at runtime.
iirc I think adonis has a command like the one that your trying to make, but it doesn’t use loadstring.
Yes, I saw that. But if it doesn’t use loadstring, what does it use then?
Why not Custom events (BindableEvents)?
They use some kind of module that runs code in a string.
I’m not familiar with those, I’m still kind of new to scripting and remotes and stuff, what does it do?
Is it complicated? I might check it out and see if I can learn anything from it
I’m pretty sure that whatever they use to run the code in a string is quite complex , but I will give you a model that might help:
Wait, is there another method I could use? Maybe with a remote event? Anything?
I’ve seen this kind of code before in lua/game “executors”, UTGs and stuff like these. I don’t understand them tho.
If you are new to scripting, you should really start with Remote/Bindable Events/Functions. I know two versions of games:
FilteringEnabled games and FilteringDisabled games.
The main difference is that FilteringEnabled games are really hard to hack. This is because with these Instances you can only run a script on the server side that make changes visibles to all other Players when you need a localscript. Suppose you create a script that prints something after the player presses the “E” key. If you do this in a local script, hackers can access it, but not on the server side. So you mean: “Yes, this is the solution! But why do we need Remote WhatWasHisName?” You need it because PlayerEvents are only found in a local script. For example, if you make a money manager for a game that gives 100 money to a player thanks to a local script, then a hacker can really easily hack in and determine how much money he gives himself (For example 1B+). To run your code server-side, you can use RemoteEvents (I never really understood why we really need BindableEvents, but my theory is that you can connect to both server code and other server code, but with Remote it’s just Server->Client or Client->Server and that you can create your own events with it)! An example would be this:
local RemoteEvent = RemoteEventPath --Your RemoteEvent Location
PlayerTouchedSomething:Connect(function() --Use a event, simply a event (srry but i am to lazy to direkt find a Event so just say you find one)
RemoteEvent:Fire() --Activate a Serverside script
end)
Es tut mir leid, aber ich bin nicht wirklich die beste Person, um es Ihnen zu erklären. Sie sollten sich ein Video auf Youtube ansehen oder einfach die API.
I know about FE and FD and how it works, no worries, I’ve just never actually dug into it. Thank you tho
Adonis uses Rerubi, and other ModuleScripts which I think converts the lua string into bytecode, but I’m not too sure. You can even use it by copying all the lua files here into ModuleScripts and using require(path to Loadstring modulescript)('lua code')()
edit: nvm the link that @DragRacer31 posted to https://www.roblox.com/library/4689019964/vLua-5-1-improved-VM is the same thing using FiOne, which is basically an updated version of Rerubi. Using it is the same as require(path to Loadstring modulescript)('lua code')()
or you could require the module using its ID and do require(4689019964)('lua code')()
if you wanted to.
Like many have said it’s risky so make sure you do it right