i want to use loadstrng to do things like make players GUI visible, but i cant figure out how. changing it on the server wont work.
Loadstring is highly restricted directly on the client due to security reasons. But you can modules and remote objects to make it work. Modules are what I prefer personally
DISCLAIMER
While this will make loadstring work on the client, I highly, and I mean HIGHLY recommend you to search for other methods as this makes your game extremely vulnerable against exploiters
local loadstringmodule = {}
function loadstringmodule.LoadGivenString(str)
local f,e = loadstring(str)
return f,e
end
return loadstringmodule
Then on the client:
local lsm = require(game.ReplicatedStorage.LoadStringModule)
local player = game.Players.LocalPlayer
local gui = --- Put your gui here
local f,e = lsm.LoadGivenString('gui.Transparency = 0')
if not f then warn(e) end
f()
Please take note I figured this out mere minutes before I saw this so this may be wrong
what could exploiters do? (im curious)
Load string basically executes the string as a code, so exploiters could pretty much do… anything.
You said that you want to make GUI visible through the script. You don’t really need load string for that. I’m assuming that you are editing the GUI through game.StarterGui
so yeah, that probably won’t do anything unless the player resets. You’ll have to edit it through game.Players.(the player).PlayerGui
I don’t recommend doing this on the server though. You should use remote events and have a separate local script that handles your UIs.
On the server script, fire that remote event when you want to make the GUI visible.
RemoteEvent:FireAllClients(true)
And then on your client script (inside Player scripts), add the remote event receiver which processes the request
RemoteEvent.OnClientEvent(function(bool)
GUI.Visible = bool
end
This should do the effect you’re looking for, also being much more efficient and secure than using loadstring.
do you know how I can get the console outputs of both clients and server? I’m making a console gui
Maybe try a custom loadstring implementation via a LuaVM?
This one looks pretty interesting
While there is no API to access the console directly, you can have remote events to capture your print messages.
Errors are a bit tricky to get so I don’t know how to currently, but if I learn how to then I’ll get back to you. Meanwhile you can search up on YouTube how to do this
Hi there @computerph1_DEV, I told you I’d get back to you if I found a way to achieve your goal. And I did. There is a service called “LogService”, specifically “LogService.MessageOut” that detects when the output outputs something. EX:
local LogService = game:GetService("LogService")
local messageLabel = Instance.new("TextLabel")
messageLabel.Parent = workspace
local function onMessageOut(message, messageType)
messageLabel.Text = "The message was " .. message .. " and the type was " .. tostring(messageType)
end
LogService.MessageOut:Connect(onMessageOut)
local LogService = game:GetService("LogService")
-- Example function to log a message
local function logMessage(message)
LogService:Log("INFO", message)
end
-- Example usage
logMessage("This is a log message.")
-- Handling logging errors
LogService.MessageOut:Connect(function(message, messageType)
if messageType == Enum.MessageType.MessageError then
print("Error: " .. message)
end
end)
I’ll leave the documentation here for you to puruse
Do take note that this is a little unreliable but it’s the best I found