attempt to index a nil value on FiveM esx_policejob - lua

attempt to index a nil value (local 'weapon')
In the first line is the error
local component = weapon.components[i]
local hasComponent = HasPedGotWeaponComponent(playerPed, GetHashKey(v.weapon), component.hash)
if hasComponent then
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_owned'))
else
if v.components[i] > 0 then
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_item', ESX.Math.GroupDigits(v.components[i])))
else
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_free'))
end
end

I am not completely sure if this works out, but that would be my solution:
Check if you have this in your script!
ESX=nil
if not write it at the top!

Related

Text is not a valid member of Frame - how do I fix that?

It gives me an error when I execute it "Text is not a valid member of Frame". It's a slider script.
--SLIDER:
local SliderFrame = script.Parent.WalkSpeedSlider
local UIS = game:GetService("UserInputService")
local WalkSpeedSlider = script.Parent.WalkSpeedSlider
local SliderFrame = WalkSpeedSlider.SliderFrame
local Slider = SliderFrame.Slider
local WalkspeedReset = SliderFrame.Reset
local WalkspeedDragging = false
local WalkSpeedDisplay = SliderFrame.WalkSpeedNum
Slider.MouseButton1Down:Connect(function()
WalkspeedDragging = true
end)
UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
WalkspeedDragging = false
end
end)
UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
if WalkspeedDragging == true then
local MouseL = UIS:GetMouseLocation()
local RelativePos = MouseL-SliderFrame.AbsolutePosition
local percent = math.clamp(RelativePos.X/SliderFrame.AbsoluteSize.X,0,1)
Slider.Position = UDim2.new(percent,0,0,0)
game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid").WalkSpeed = math.round(percent*120)
WalkSpeedDisplay.Text = math.round(game.StarterPlayer.CharacterWalkSpeed)
end
end
end)
I was trying to make a slider which I succeeded, but I wanted my textbox which is WalkSpeedDisplay to be able to change to the speed that I put with the slider, but WalkSpeedDisplay.Text gives me an error "Text is not a valid member of Frame" and I don't know why.
Frames don't have a property known as text. If you want to add text to a frame, insert a text label in the frame and customize it to how you want.
I may be wrong about this, it would be helpful to see all the children and parents of the frame.
Also you probably shouldn't use a variable name two times, such as you did with SliderFrame.

i have this issue "Workspace.hugyuihjoih.LocalScript:4: attempt to index nil with 'Destroy'"

local BackPack = game.Players.LocalPlayer.Backpack
game.Players.LocalPlayer.leaderstats.Strength.Changed:Connect(function()
if game.Players.LocalPlayer.leaderstats.Strength.Value >= 30 and game.StarterPack.Weight.Equipped then
game.Players.LocalPlayer.Character:FindFirstChild("Weight"):Destroy()
local DoubleWeight = game.ReplicatedStorage.Tools.DoubleWeight:Clone()
DoubleWeight.Parent = BackPack
if game.StarterPack.Weight.Unequipped and game.Players.LocalPlayer.leaderstats.Strength.Value >= 30 then
BackPack:FindFirstChild("Weight"):Destroy()
end
end
end)
game.Players.LocalPlayer.Character:FindFirstChild("Weight") returns a nil value, hence you may not index it with Destroy as in game.Players.LocalPlayer.Character:FindFirstChild("Weight"):Destroy()
You need to check wether that value exists befor you attempt to index it.

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 error making 16x16 grid

The following code gives me the following error:
attempt to index a nil value
-- Making grid
grid = {}
local i = 1
local ii = 1
mainx, mainy = love.graphics.getDimensions()
while(i<=mainx) do
if(i%16==0) then
while(ii<=mainy) do
if(ii%16==0) then
grid[i][ii] = nil
end
ii = ii + 1
end
end
i = i+1
end
I know lua is 1-based, but i dont really know what goes wrong here.
A fix will be gladly appericated :)
NOTE: mainx, mainy should be 800 and 600.
You forgot to assign grid[i] to {} before doing grid[i][ii] = nil. Second dereferencing [ii] fails because grid[i] == nil
I refactored your code below a little.
-- Making grid
local grid = {}
local mainx, mainy = love.graphics.getDimensions()
for i = 16,mainx,16 do -- syntax: for i = <start_value>, <max value (included)> [, <step>]
grid[i] = {};
for ii = 16,mainy,16 do
grid[i][ii] = i*ii -- some value
end
end

Attempt to index field 'other'

What is the problem here? This code is supposed to remove texts after I shoot it and at the same time increasing the score. Also, can someone explain what does the other.name actually mean? I don't quite fully understand it..(And yes its the first if statement that has the error)
function wordCollision(e)
if (e.other.name == 'balloonText') then -- error here: attempt to index field 'other'(a nil value)
display.remove(e.other)
e.other = nil
score.text = score.text + 50
score.anchorX = 0
score.anchorY = 0
score.x = 200
score.y = 50
target.text = target.text - 1
else
if (e.other.name == 'balloonTextt') then
display.remove(e.other)
e.other = nil
score.text = score.text + 50
score.anchorX = 0
score.anchorY = 0
score.x = 200
score.y = 50
target.text = target.text - 1
end
end
end
It simply means that there is no entry with key 'other' in the table e.
If if you want to look up something in e.other you'll have to assign a table to that key:
e.other = {}
Using metatables, you could make it go automatically:
mt = {}
mt.__index=function(t,k) if ~rawget(t,k) then t[k]=setmetatable({},mt) end return t[k] end
e={}
e=setmetatable(e,mt)
e.other.name='foo'
Watch out with this though, because any lookup to a non-existant field will create a new table for it, which may or may not be what you want (aside of the fact that this overwrites any existing metatable on e):
for k,v in pairs(e) do print(k,v) end
print(e.bar)
for k,v in pairs(e) do print(k,v) end
Problem could be that you have the e.other = nil in there, but don't reset e.other to something after, so when the wordCollision() gets called again, it is e.other is nil. Could also be that e.other is never initialized in the first place. Verify it is initialized somewhere before wordCollision() is ever called, and verify that it is re-set to something between two calls to wordCollision().

Resources