I want this for my admin commands of my game . So i already said whar i want in title , for example if 1 admin says workspace.BasePlate.Color=Color3.fromRGB(255,255) it gets executed, yeah, . Please help
u can use /console, press server then write the command for it to execute
I want to do it with chat messages not commands , the admin rank of my game wont be in builder team …
so u wanna make custom commands?
Edit: Just as an additional point. Allowing users to use loadstring in your game is risky, even if it’s only for “trusted” users. Without modifying the executed code’s environment, they can potentially have access to everything in your game. That could go from injecting exploits/viruses into that instance, all the way to modifying datastore values to potentially break your game for others. I’d recommend making certain modifications to the environment (using getfenv/setfenv) to ensure that sensitive services/instances can’t be accessed.
Here’s a similar article that might help you out some more: How to use loadstrings?
loadstring? Okay , almost forgot about that function, and it’s okay , i dont think if this is really dangerous to be activated, cause exploiters usually use it to send a http request, right ?
Yes it is easily exploitable if not protected against. You will likely want to setfenv the returned function before running so you can replace the DataModel with your own restricted DataModel (without HttpService, DataStoreService etc.). Also important to remove the ability for loadstrings to call further loadstrings, so would be good to overwrite that function.
There are modules that I don’t have experience with: vLua: Loadstring reimplemented in Lua - #6 by 2unkens that might be worth a look at.
This post has some good examples of how to assign a new environment to a function, as well as some of the techniques and potential vulnerabilities that you may have to mitigate against.
Ultimately allowing users to run un-moderated code in any game always carries a risk, and should be avoided unless it’s core to the game.
If you only need this functionality for specific examples, such as “workspace.BasePlate.Color=Color3.fromRGB(255,255)”, then that’s something that you can hard-code into its own command by itself: “:Colour workspace.BasePlate 255 255 255” etc.
-- This is not recomended, create custom commands instead of using loadstring!
local Admins = {"Names Here"}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(chatstring)
local Allowed = false
for i in pairs(Admins) do
if plr.Name == Admins[i] then
Allowed = true
end
end
if Allowed == true then
local succes, fail = pcall(function() -- For not spamming console when typing normal
loadstring(chatstring)()
end)
end
end)
end)
Create custom commands, its easyer to use and safer, and its easyer to create custom ranks with diferent permissions too.
To be honest this is sad that os.execute() which exists in Lua 5.4 doesn’t exist in roblox . Anyways ty for informations