Currently I am trying to execute code I have stored on a webserver.
I can successfully print out the code and it all looks okay, but when I try run it using loadstring it gives me the following error
I have LoadstringEnabled set to true and the scripts RunContext on Legacy.
Here’s an example codeblock of what I am doing just with a swapped uri
local code = game:GetService("HttpService"):GetAsync("https://example.com/script/raw.txt")
local func, err = loadstring(code)
if code == nil then
print(err)
else
func()
end
The reason you are getting this error is because the returned code to the loadstring is not a function. Instead it is a bunch of code that has already been executed.
How would I go about having this code executed in game? What’s being passed through to me appears to be a string value. So I don’t see how this could have been executed in game already.
i think loadstring returns evaluation result.
from your error which is attempt to call a nil value, i can tell your code from your webserver doesnt return anything / returns nil
local code = game:GetService("HttpService"):GetAsync("https://example.com/script/raw.txt")
local res, err = pcall(function()
return loadstring(code)
end)
if err then
print(err)
else
print("RESULT", res)
end
local code = game:GetService("HttpService"):GetAsync("https://example.com/scripts/bans/raw.txt")
local load, err = loadstring(code)
if load ~= nil then
load()
else
print(err)
end
raw:
local ban_script = game:GetService('HttpService'):GetAsync('https://example.com/scripts/bans/subscript.txt')
local code = loadstring(ban_script)
code()
subscript:
-- | Connections
local HTTPService = game:GetService("HttpService")
local Players = game:GetService("Players")
-- | Variables
local banAPI = "https://api.example.com/IsUserBanned.ashx/"
local ConsolePrefix = "Example Bans: "
-- | Connections
Players.PlayerAdded:Connect(function(player)
local response = HTTPService:GetAsync(banAPI..player.UserId)
local deserialized = HTTPService:JSONDecode(response)
if not response then
player:Kick(ConsolePrefix.."Failed to connect to BanAPI")
end
if deserialized.Status ~= "OK" then
player:Kick(ConsolePrefix..deserialized.Status)
end
if deserialized.Banned == true then
player:Kick(ConsolePrefix..deserialized.BanReason)
end
end)
If you are wondering why there is 2 scripts on the webserver, this is because I will be hiding the 2nd one by obfuscating the first webserver script so people cant access the second one.
local code = game:GetService("HttpService"):GetAsync("https://example.com/scripts/bans/raw.txt")
print("CODE", code)
local load, err = loadstring(code)
if load ~= nil then
load()
else
print(err)
end
then screenshot the output (reminder to censor your url)