LUA Error: attempt to index a nil value #6:16 - lua

I am trying to retrieve the Entryhandle UUID by sending a request. However, I am getting this error every time. Can anyone help me solve it or point out where I am making a mistake?
local config={}
config.mcast_mac = "00:0a:cd:16:da:f1"
function rpc:epm()
local pkt = CreateFromPath("ethernet/ip/udp/dcerpc/epm")
--[[data is put here]]
SendAndWait(pkt, function(res)
local epm = res.get_layer("epm")
--[[data is put here--]]
handle = epm.EntryHandleUUID.to_string()
print("EntryHandleUUID:",handle)
end
end,2000)
return handle
end

This code not valid Lua code. Suppose remove end from line after print.
To findout where you try get access to nil value you can just add assert before each index operation.
local config={}
config.mcast_mac = "00:0a:cd:16:da:f1"
assert(rpc, 'rpc is NULL')
function rpc:epm()
local pkt = CreateFromPath("ethernet/ip/udp/dcerpc/epm")
--[[data is put here]]
SendAndWait(pkt, function(res)
assert(res, 'res is NULL')
local epm = res.get_layer("epm")
--[[data is put here--]]
assert(epm, 'epm is NULL')
local uuid = epm.EntryHandleUUID
assert(uuid, 'epm.EntryHandleUUID is NULL')
handle = uuid.to_string()
print("EntryHandleUUID:",handle)
end, 2000)
return handle
end

Related

Can anyone tell me that the error "calling xxxx on bad self" shows

I use lua in Unity. When I call the function **TryDisableHeadWear **, there are some error I can't understand.
calling 'GetSurfaceName' on bad self (string expected, got nil)
function def:TryDisableHeadWear()
if not self:CheckSurfaceName(self._hat_go) then
self._hat_go:SetActive(false)
end
end
function def:CheckSurfaceName(obj)
local surface_name = self:GetSurfaceName(obj)
return head_wear_surface[surface_name] ~= nil
end
local reg = "(%w+)"
function def:GetSurfaceName(obj)
if not obj then return end
local root_obj = self:GetSurfaceObj(obj)
local surface_obj_name = root_obj and root_obj.name
return surface_obj_name and string.match(surface_obj_name, reg)
end
function def:GetSurfaceObj(obj)
if string.find(obj.name, "Surface") then
return obj
else
local parent = obj.transform.parent
if not parent then return end
return self:GetSurfaceObj(parent.gameObject)
end
end
Can anyone tell me what the error means?
I try to call the function in normal environment. I get no error and everything goes well. But where are some error report in firebase that means the code above has bugs

Attempt to index a boolean value error when calling this function

I get the attempt to index a boolean value error when calling this function:
M.on_attach = function(client, bufnr)
if client.name == "tsserver" then
client.resolved_capabilities.document_formatting = false
end
lsp_keymaps(bufnr)
lsp_highlight_document(client)
end
Can anyone help me?
Edit:
I get the error on the second line here:
local opts = {
on_attach = require("s3m.lsp.handlers").on_attach,
capabilities = require("s3m.lsp.handlers").capabilities,
}
require("s3m.lsp.handlers") returns true which is a boolean value. with require("s3m.lsp.handlers").on_attach you index that nil value which is an invalid operation in Lua.
For this to make sense your required script must return a value. In your case M
require returns true if the script is loaded successfully but does not return a non-nil value. Please read the manual to avoid such errors.

How can I send arguments through to a client from server using RemoteEvent? ROBLOX

My goal here is to send the player object and the object name through to the client script to display the object name on a text label.
When I run this, it prints nil and nil. I want player.Name and name as you will see in the second code sample. Another error I get is "attempt to concatenate nil with string" from the client script.
Here is my server-side code:
script.onTouch.OnInvoke = function(button, sellObj, sellObjValue, buyObj, buyObjValue, afterWave, isLoadedPart)
if isLoadedPart == true then
local info = script.Parent.Parent.info
local player = info.player.Value
local owner = info.owner.Value
local savedItems = info.savedItems.Value
local builds = script.Parent.Parent.activeBuilds
if afterWave > info.activeWave.Value then
info.activeWave.Value = afterWave
end
button.Parent = savedItems.buttons
button.jobDone.Value = true
if sellObj ~= nil then
sellObj.Parent = savedItems.builds
end
if buyObj ~= nil then
buyObj.Parent = builds
end
local td = require(script.Parent.tycoonDictionary)
if not table.find(td.boughtButtons, button.objectId.Value) then
table.insert(td.boughtButtons, button.objectId.Value)
end
local ui = game.ReplicatedStorage:FindFirstChild('onPartLoad')
if ui then
ui:FireClient(player, 'buyObj.Name')
print('yes')
else
print('no')
end
else
local info = script.Parent.Parent.info
local player = info.player.Value
local owner = info.owner.Value
local money = info.player.Value.leaderstats.Money
local savedItems = info.savedItems.Value
local builds = script.Parent.Parent.activeBuilds
if money.Value >= buyObjValue or money.Value == buyObjValue then
if afterWave > info.activeWave.Value then
info.activeWave.Value = afterWave
end
button.Parent = savedItems.buttons
button.jobDone.Value = true
if sellObj ~= nil then
sellObj.Parent = savedItems.builds
money.Value += sellObjValue
end
if buyObj ~= nil then
buyObj.Parent = builds
money.Value -= buyObjValue
end
local td = require(script.Parent.tycoonDictionary)
if not table.find(td.boughtButtons, button.objectId.Value) then
table.insert(td.boughtButtons, button.objectId.Value)
warn(td.boughtButtons)
end
else
player.PlayerGui.inGame.error.label.invokeScript.errorInvoke:Invoke("Insufficient Funds")
end
end
script.Parent.waveChecker.afterRun:Invoke()
end
And here is my client-side code:
game.ReplicatedStorage.onPartLoad.OnClientEvent:Connect(function(player, name)
print(player.Name, name)
print(script.Parent.Text)
script.Parent.Text = name .. 'is loaded.'
print(script.Parent.Text)
end)
Here I will tell you a little about this game. It is a tycoon that saves data using a table with all button Ids in it. When it loads, it gets the button associated with the id and fires the server code for every button. If the button is a load button, it fires the client with the player and the buyObj.Name.
Is there just a little mistake or can I not send arguments to the client at all? Any help will be appreciated!
The OnInvoke callback's first argument is always the player that fired it, so you should change line 1 of the first script to:
script.onTouch.OnInvoke = function(playerFired, button, sellObj, sellObjValue, buyObj, buyObjValue, afterWave, isLoadedPart)
And :FireClient() requires a player argument as its first argument, so you should change
ui:FireClient(player, 'buyObj.Name')
to
ui:FireClient(playerFired, player, 'buyObj.Name')
Here is the solution I came up with;
First, I read through some Roblox documentation to find that the first argument I had to send when using :FireClient was the player, and because I already had the player there, it was just sending the function to that player. Now, I had 2 choices, I could send the player twice, or delete the player variable from the script. I chose the second one.
Here is what the :FireClient line in the server script looks like now:
game.ReplicatedStorage:WaitForChild('onPartLoad'):FireClient(player, buyObj.Name)
And here is what the client function script looks like now:
game.ReplicatedStorage.onPartLoad.OnClientEvent:Connect(function(name)
if name ~= 'starterFoundation' then
script.Parent.Text = name .. ' is loaded.'
end
end)
Thank you #TypeChecked for helping me realize this!

LUA using function variable outside of it

I am trying to edit a script in LUA but I couldn't get access of a local defined in a function
LUA Code
function getSafeMoney()
local SafeMoney = nil
QBCore.Functions.ExecuteSql(false, 'SELECT * FROM `moneysafes` WHERE `safe` = "mechanic"', function(result)
SafeMoney = json.decode(json.encode(result[1])).money;
end)
return SafeMoney
end
print(getSafeMoney())
Result :
nil
here's the sql function as sysdevs asked
QBCore.Functions.ExecuteSql = function(wait, query, cb)
local rtndata = {}
local waiting = true
exports['ghmattimysql']:execute(query, {}, function(data)
if cb ~= nil and wait == false then
cb(data)
end
rtndata = data
waiting = false
end)
if wait then
while waiting do
Citizen.Wait(5)
end
if cb ~= nil and wait == true then
cb(rtndata)
end
end
return rtndata
end
Your second function is not holding the main function I assume, I am bad at lua aswell, but I think that changing
QBCore.Functions.ExecuteSql(false, ............
to
QBCore.Functions.ExecuteSql(true, ............
This will probably fix your problem, still your code is ambiguous and needs concentration if you could provide more information I might be able to help more

How to fix NPCs not spawning

I coded out some functions in a ModuleScript to be executed by another script. Here is the code
local module = {}
wavepause = game.ReplicatedStorage.Values.WavePauseLength.Value
trollanoid = game.ReplicatedStorage.Trollanoid
spawnpoints = workspace.Test1.Spawns:GetChildren()
function trollanoidsummon()
local chosenspawn = math.random(#spawnpoints)
local clone = trollanoid:Clone().Parent == workspace.Zombies
clone.HumanoidRootPart.CFrame = chosenspawn.CFrame
end
module.Wave1 = function()
trollanoid()
wait(1)
trollanoid()
wait(1)
trollanoid()
wait(1)
trollanoid()
end
return module
What I expected was the NPC trollanoids to appear on the map, but instead I got this error in the output:
17:50:19.011 ServerScriptService.WaveModule:14: attempt to call a Instance
value  -  Server  -  WaveModule:14
I dont know what I did wrong, please help me fix this. Any help is appreciated
The error message is telling you what's wrong:
You're trying to call an object. The only things you can call in Lua are functions and objects with the __call metamethod.
You are calling an object. Like mentioned above, you can only call functions and objects with __call metamethod.
Try this:
local module = {}
wavepause = game.ReplicatedStorage.Values.WavePauseLength
trollanoid = game.ReplicatedStorage.Trollanoid
spawnpoints = workspace.Test1.Spawns:GetChildren()
function trollanoidsummon()
local chosenspawn = spawnpoints[math.random(#spawnpoints)]
local clone = trollanoid:Clone().Parent = workspace.Zombies
clone.HumanoidRootPart.CFrame = chosenspawn.CFrame
end
module:SpawnNPC(amount, threshold)
threshold = threshold or 1
amount = amount or 4
for i = 1, amount do
if wavepause.Value then break end;
trollanoidsummon()
wait(threshold)
end
end
return module
To use the module you would do this:
local spawner = require(modulescriptpath);
spawner:SpawnNPC(5, 1);
I made a few minor changes. Let me know if you need help with any :)

Resources