Attemp to call a nil value (field ‘ShowInventory’) [ESX2] - lua

I just installed ESX 2 into my new server, im Really new at lua and i dont really know what i should do with some resources or how to start coding
I wan to work in the inventory system based on es_extended, but, it doesnt work.
I press the Inventory Key informed in the cofig file \server-data\resources\es_extended\config\default\config.lua
“Config.InventoryKey = “REPLAY_START_STOP_RECORDING_SECONDARY” – Key F2 by default”
module.InitESX = function()
module.RegisterControl(module.Groups.MOVE, module.Controls[Config.InventoryKey])
module.On('released', module.Groups.MOVE, module.Controls[Config.InventoryKey], function(lastPressed)
print("Comment before show The Inventory")
ESX.ShowInventory()
-- if Menu.IsOpen ~= nil then
-- if (not ESX.IsDead) and (not Menu.IsOpen('default', 'es_extended', 'inventory')) then
-- ESX.ShowInventory()
-- end
-- end
end)
end
I literally change a little bit the code to directly execute the ShowInventory() Function but i got this error
the original code look like this
module.InitESX = function()
module.RegisterControl(module.Groups.MOVE, module.Controls[Config.InventoryKey])
module.On('released', module.Groups.MOVE, module.Controls[Config.InventoryKey], function(lastPressed)
if Menu.IsOpen ~= nil then
if (not ESX.IsDead) and (not Menu.IsOpen('default', 'es_extended', 'inventory')) then
ESX.ShowInventory()
end
end
end)
end
but when i press the key dont do nothing and doesnt show anything in the console.

Related

Error with getting TextBox data and manipulating it - CLOSED -

Before I start, I will say that there are no error messages in the console, of any type. Anyway, I have been trying to make a user tools game where a player can look at their avatar, look like them, etc. It used to work well in the default Roblox chat, but since that gets moderated, I made a "chat bar" for my game. However, now only one of these functions works (AvatarInspectMenu with a UserId, and not a username). Take a look for yourself:
-- client script
local Players=game:GetService("Players")
local Player=Players.LocalPlayer
local StarterGui=game:GetService("StarterGui")
local GuiService=game:GetService("GuiService")
local Rep=game:GetService("ReplicatedStorage")
repeat wait(0.1) until Player.Character
local h=Player.Character:WaitForChild("Humanoid")
StarterGui:SetCore("TopbarEnabled",false)
local ChatBar=Player.PlayerGui:WaitForChild("ScreenGui").Frame.BoxFrame.Frame.ChatBar
GuiService:SetInspectMenuEnabled(false)
local CS=game:GetService("ContextActionService")
CS:BindAction("Chat Focus",function()
ChatBar:CaptureFocus()
end,false,Enum.KeyCode.Slash)
function ID(str)
if tonumber(str)~=nil then
return tonumber(str)
else
return Rep.Idify:InvokeServer(str)
end
end
ChatBar.FocusLost:Connect(function(entr)
if not entr then return end
ChatBar:ReleaseFocus(true)
local m=ChatBar.Text
ChatBar.Text=""
if m=="!reset" then
Rep.Desc:InvokeServer(Player.UserId)
end
if h.Sit then
if #string.split(m," ")==1 then
local id=ID(m)
if h.SeatPart.Name=="AvatarInspectMenu" then
GuiService:InspectPlayerFromUserId(id)
end
if h.SeatPart.Name=="Become" then
local Desc=Rep.Desc:InvokeServer(id)
h.Sit=false
end
if h.SeatPart.Name=="Tep" then
local P,J=Rep.Join:InvokeServer(id)
if not (P and J) then return end
game:GetService("TeleportService"):TeleportToPlaceInstance(P,J,Player)
end
end
end
end)
-- server-side script
local cache={}
local rep=game:GetService("ReplicatedStorage")
rep.Idify.OnServerInvoke=function(_,n)
if cache[n] then return cache[n] end
local player=game.Players:FindFirstChild(n)
if player then
cache[n]=player.UserId
return player.UserId
end
local id
pcall(function ()
id=game.Players:GetUserIdFromNameAsync(n)
end)
if not id then return 156 end
cache[n]=id
return id
end
local dcs={}
rep.Desc.OnServerInvoke=function(p,n)
if not dcs[n] then
pcall(function()
dcs[n]=game:GetService("Players"):GetHumanoidDescriptionFromUserId(n)
end)
end
p.Character.HumanoidRootPart.CFrame=CFrame.new(0,10,0)
if not dcs[n] then
p.Character.Humanoid:ApplyDescription(game:GetService("Players"):GetHumanoidDescriptionFromUserId(156))
return false
else
p.Character.Humanoid:ApplyDescription(dcs[n])
return true
end
end
rep.Join.OnServerInvoke=function(_,n)
local id,jb=nil
pcall(function()
id,jb=game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(n)
end)
if id and jb then return id, jb else return nil end
end
I've looked through the code, but I can't seem to find any problems (Except, of course, that there is no error message while trying to attempt a teleport in Studio). Help would be greatly appreciated!
Edit: This code is fully functional. No more help is needed! :D
If there is no error then it works, maybe you missed something out which wasn't called, try adding some prints within functions to see if it prints.

attempt to index global 'message' (a nil value) Lua Message script

Currently, I'm working on a simple Lua Roblox script that is supposed to turn the parent part blue when "/blue" is entered in the chat by ANY player. When run, it returns the error "attempt to index global 'message' (a nil value)" in the output. Also, when I hover my cursor over "message" it says "unknown global 'message'". I am sure I'm doing something terribly wrong as I am new to the language. I have tried moving the script into Workspace and Chat (of course changing local part when I do) but those don't help. I'm confident it's a code issue specifically defining a global variable.
local part = script.Parent
local function scan()
if message:sub(1,5) == "/blue" then
part.BrickColor = BrickColor.Blue()
end
end
scan()
First, you didn't define "message" because "message" is supposed to be an argument of
player.Chatted()
So instead of just running scan(), make multiple functions, here is the revised code:
local part = script.Parent
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
message = string.lower(message)
if message == "/blue" then
part.BrickColor = BrickColor.new("Blue")
end
end)
end)
Let me know if you need me to elaborate, I understand that sometimes this stuff can be confusing.

Roblox How to detect a player's team

I am making a Roblox game, and I need to detect a player's team somehow.
My code currently looks like this:
script.Parent.Touched:Connect(function(part)
local plr = part.Parent.Name
if (game.Players:FindFirstChild(plr).Team == "Police") then
....
end
end)
And when I touch that part (it's an invisible wall), it gives me an error: Workspace.Part.Script:3: attempt to index a nil value
What am I doing wrong?
Edit: I found out it can't find my name in game.Players, because now I tried:
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:FindFirstChild(hit.Parent.Name)
if (plr.Team == "Police") then
...
And now I get Workspace.Part.Script:3: attempt to index local 'plr' (a nil value)
Edit2: Now I tried printing plr (game.Player:FindFirstChild(hit.Parent.Name)) and it was ' Miniller', not 'Miniller', and now I didn't get any errors, but the code below also did nothing..
I solved it by not using variables AND not "Police", it's game.Teams.Police, so code:
if (game.Players:FindFirstChild(hit.Parent.Name).Team = game.Teams.Police
...

Why would this script not work?

The following script breaks between print("2") and print("3") because it cannot find the variable "tag". How would I fix this?
local Humanoid = script.Parent.Zombie -- Or Zombie Or Whatever
function PwntX_X()
print("1")
local tag = Humanoid:findFirstChild("creator")
print("2")
if tag ~= nil then
print("3")
if tag.Value ~= nil then
print("4")
local Leaderstats = tag.Value:findFirstChild("leaderstats")
print("5")
if Leaderstats ~= nil then
print("6")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 5
print("7")
wait(0.1)`enter code here`
script:remove()
end
end
end
end
Humanoid.Died:connect(PwntX_X)
I already have a script for the leaderboard that works 100%. This script is being used for a game called "ROBLOX". Thanks!
Alright, first off, scriptinghelpers.org was created as a service similar to stackoverflow specifically for Roblox, I suggest next time, you ask there, now on to stuff;
-- If you have further problems, My Roblox username is 'ZeroBits' (REMOVE THIS LINE)
DEBUG = true -- Debug Print, so you can disable it when you're done.
local function print_D(t)
if DEBUG == true then warn(t) end end
print_D("DEBUG MODE, Switch Debug Value to False when finished")
local Humanoid = script.Parent:FindFirstChild("Zombie") -- We'll use FindFirstChild() here
--if not Humanoid then -- Uncomment this statement if you want it to affect objects named Humanoid as well
-- Humanoid = script.Parent:FindFirstChild("Humanoid")
--end
function HumanoidKilled() -- Renamed the function to be a little less cringeworthy
print_D("1") -- switched these print statements with the Print_D() function
local tag = Humanoid:FindFirstChild("creator") -- Capitalized the first letter in FindFirstChild()
print_D("2")
if not tag then
warn("No Tag Found check Humanoid and weapon script") --if this prints, there's either no tag, or a serious problem, and you should check the humanoid object for a tag, or make sure the weapons you use actually generate tags.
else -- changed 'if tag ~= nil then' to 'if not tag then 'do stuff' else' to simplify the code, and add an else statement early on.
print_D("3")
if tag.Value then -- removed '~= nil' because it's just useless clutter
print_D("4")
local Leaderstats = tag.Value:findFirstChild("leaderstats")
print_D("5")
if Leaderstats ~= nil then
print_D("6")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 5
print_D("7")
wait(0.1)
script:Destroy() -- switched remove() to Destroy(), remove() is deprecated
end
end
end
end
Humanoid.Died:connect(HumanoidKilled)
This fixes all the problems in the script, and makes it more efficient. if there are still problems, it's either in the tag creation script, the tags aren't stored in the humanoid, or the tags aren't named 'creator'
also, I switched over the print statements to a print_D function, which uses warn() rather than print() there's almost no difference, except that the debug text will appear yellow in the console, rather than white.
script is being used for a game called "ROBLOX". Thanks!
It's for a game On Roblox, not a game called Roblox, what you said is akin to saying; I made this mod for Source Engine, when you actually made the mod for Half-Life 2

Awesome WM (v3.5.5) keygrabber alternative

I've never liked the default window switching possibilities in Awesome, so I thought I'd implement Alt-Tab behavior that takes history into account (and does fancy opacity effects).
When Alt-Tab is pressed, the entire history is recorded in a table, and appended to that history are the minimized windows (within the same tag). When this table is generated, I instantiate a keygrabber that captures Tab-press events (to switch to the next client in the table) and Alt-release events (to abort entirely).
A flag keeps track of whether the user is in the process of Alt-tabbing, to prevent the table from being generated over and over again.
The code (it's a lot and you probably don't need to see it, but my experience tells me that when I don't post all the code, people will ask for it eventually):
altTabbing = false
altTabIndex = 1
altTabHistory = {}
clientOpacities = {}
function altTabSetOpacities(restore)
for i,c in pairs(altTabHistory) do
if not restore and i ~= altTabIndex then
c.opacity = 0.5
else
c.opacity = clientOpacities[i]
end
end
end
function myAltTab()
-- First check if the user is already alttabbing, in which case the history
-- should NOT be updated. If the user has just pressed alt-tab, generate a new
-- history-table
if not altTabbing then -- generate history-table
-- Clear Tables
for i in pairs(altTabHistory) do altTabHistory[i] = nil end
for i in pairs(clientOpacities) do clientOpacities[i] = nil end
-- Get focus history for current tag
local s = mouse.screen;
local idx = 0
local c = awful.client.focus.history.get(s, idx)
while c do
table.insert(altTabHistory, c)
table.insert(clientOpacities, c.opacity)
idx = idx + 1
c = awful.client.focus.history.get(s, idx)
end
-- Minimized clients will not appear in the focus history
-- Find them by cycling through all clients, and adding them to the list
-- if not already there.
-- This will preserve the history AND enable you to focus on minimized clients
local t = awful.tag.selected(s)
local all = client.get(s)
for i = 1, #all do
local c = all[i]
local ctags = c:tags();
-- check if the client is on the current tag
local isCurrentTag = false
for j = 1, #ctags do
if t == ctags[j] then
isCurrentTag = true
break
end
end
if isCurrentTag then
-- check if client is already in the history
-- if not, add it
local addToHistory = true
for k = 1, #altTabHistory do
if altTabHistory[k] == c then
addToHistory = false
break
end
end
if addToHistory then
table.insert(altTabHistory, c)
table.insert(clientOpacities, c.opacity)
end
end
end
-- reset current index and flag
altTabIndex = 1
altTabbing = true
-- Now that we have collected all windows, we should run a keygrabber
-- as long as the user is alt-tabbing:
keygrabber.run(
function (mod, key, event)
-- Stop alt-tabbing when the alt-key is released
if key == "Alt_L" and event == "release" then
altTabbing = false
altTabSetOpacities(true)
c = altTabHistory[altTabIndex]
client.focus = c
c:raise()
return false -- stop keygrabber
end
-- Move to next client on each Tab-press
if key == "Tab" and event == "press" then
myAltTab()
return true -- keep going
end
return true -- keep going
end
)
end -- if not altTabbing
-- at this point, the user is alt-tabbing, so we should raise
-- the next client in the history-table
if #altTabHistory < 2 then return end
-- Switch to next client
altTabIndex = altTabIndex + 1
if altTabIndex > #altTabHistory then
altTabIndex = 1 -- wrap around
end
-- focus on current client
local c = altTabHistory[altTabIndex]
c.minimized = false
c:raise()
-- make current client stand out
altTabSetOpacities(false)
end
I realize there's a lot of code, but the main thing is the keygrabber. For still unknown reasons, Awesome sometimes crashes while I'm Alt-Tabbing using this approach. I want to replace the keygrabber by connecting signals to the Alt and Tab keys, and disconnecting them as soon as the user is done. However, I'm not able to do this for some reason.
I instantiate a new key-object like this:
local altkey = awful.key({}, "Alt_L")[1]
I found out by trial and error that awful.key() actually returns a table of which I could query the first element for key, keysym etc, hence the [1]. However, when I try to connect a signal to this object, the LUA interpreter complains and tells me it's a nil object. So my question is: am I doing the right thing here? Is it even possible to replace the keygrabber in the way I intend to?
To use the Alt_L key in Awesome you should refer to "Mod1" in your rc.lua file, to make it mor readable I added the following line to the beginning of my configuration so Alt_L can be used.
Alt_L = "Mod1"

Resources