Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to handle chat messages
- local function onChat(message, player)
- -- Execute the code within the message using loadstring and pcall
- local success, dynamicFunction = pcall(loadstring, message)
- -- Display the result or error message
- if success then
- local status, error = pcall(dynamicFunction)
- if status then
- print("Code executed successfully!")
- else
- print("Error executing code: " .. tostring(error))
- end
- else
- print("Error loading code: " .. tostring(dynamicFunction))
- end
- end
- -- Connect the onChat function to the Chatted event of the Players service
- game.Players.PlayerAdded:Connect(function(player)
- player.Chatted:Connect(function(message)
- onChat(message, player)
- end)
- end)
- -- Function to execute the code received from chat using loadstring
- local function executeCodeFromChat(code)
- local success, dynamicFunction = pcall(loadstring, code)
- -- Display the result or error message
- if success then
- local status, error = pcall(dynamicFunction)
- if status then
- print("Code executed successfully!")
- else
- print("Error executing code: " .. tostring(error))
- end
- else
- print("Error loading code: " .. tostring(dynamicFunction))
- end
- end
- -- Example usage: execute code from chat
- local codeFromChat = "!print('Hello, World!')"
- executeCodeFromChat(codeFromChat)
- [[I apologize for the confusion. It seems that the loadstring function may not be available due to security restrictions in certain contexts, such as server-side scripts in Roblox Studio.
- If you encounter the error "loadstring() is not available," it means that the loadstring function is disabled in that context. This is a security measure to prevent potentially malicious code execution.
- In order to execute dynamic code in a safe and controlled manner, you might consider alternative approaches, such as creating a set of predefined commands or functions that users can trigger with chat messages. This allows you to control and validate the user input more effectively.
- Remember to prioritize security and carefully review any code that involves executing user-submitted content to prevent any potential vulnerabilities]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement