I’m trying to make an SB system with loadstring()
and vLua, I’ve figured out how to get localscripts working with vLua, but loadstring()
is erroring for some odd reason.
Error:
Workspace.Script:11: attempt to call a nil value - 48
Code (Serverside):
function LoadSS(player, _script)
local newVariables = {
["NLS"] = "function(str) local str = str..'local owner = game.Players[\'"..player.Name.."\'] ' print(str) game.ReplicatedStorage.LoadLocal:FireClient(owner, str) end ";
}
local NS = "local owner = game.Players['"..player.Name.."'] "
for name, code in pairs(newVariables) do
NS = NS .. "local "..name .." = "..code .. " "
end
NS ..= _script
print(NS)
local Successful, Response = pcall(function() local s = loadstring(NS)() return s end)
return Response
end
-- This code is just an example that I've written a while ago for VSB
wait(5)
local a = LoadSS(game.Players:WaitForChild('infiniteRaymond'), [[
local p = owner
local char = p.Character
local p = Instance.new('Part', char)
p.Name = "CameraPart"
p.Anchored = true
p.CanCollide = false
local m = Instance.new('SpecialMesh', p)
m.MeshId = "rbxassetid://2540333271"
m.TextureId = "rbxassetid://2540333290"
m.Scale = Vector3.new(1,1,1)
local remote = Instance.new('RemoteEvent', char)
remote.Name = "CameraRemote"
remote.OnServerEvent:Connect(function(player, cf)
p.CFrame = cf * CFrame.Angles(0, math.rad(180), 0)
end)
NLS("
local p = game.Players.LocalPlayer
local char = p.Character
local remote = char.CameraRemote
local part = char.CameraPart
part.Transparency = 1
game:GetService('RunService').Heartbeat:Connect(function()
remote:FireServer(workspace.CurrentCamera:GetRenderCFrame())
end)
", char)
]])
print(a)
It prints the script with the NLS
and owner
code at the top, but still errors none-the-less.
Am I using loadstring()
wrong?