Hey developers, I am currently making a system to store code off roblox but my Http request goes through but my code does not run and I don’t know why.
Server Script:
local httpservice = game:GetService("HttpService")
local response = httpservice:GetAsync("http://localhost:5265/noob")
function load()
loadstring(response)
end
wait(5)
load()
Web Server Script:
const express = require('express');
var app = express();
const bodyparser = require('body-parser');
app.use(bodyparser.urlencoded({ extended: false }));
app.use(bodyparser.json());
app.get('/noob', (req, res) => {
res.send(`print("Hello World")`)
console.log("REC")
});
app.listen(5265, () => {
console.log(`App is listening on port 5265`)
});
If you can help with this please leave a post below.
loadstring returns a function when it succeeds, and nil followed by an error string when it fails. You aren’t handling either case here. For the code to run, you should be calling the function returned after ensuring there were no errors.
-- func is nil when there's an error
local func, err = loadstring(code)
if func == nil then
print(err) -- you might want to handle the error some other way
else
func() -- this calls the function with your code
end