So I have this script:
player.Character.Humanoid:EquipTool(player.Backpack["slot"..key.ThingOccupying.Value])
“key” is the number that the player pressed, and ThingOccupying is a string value that contains the name of the tool occupying that slot. The images that represent the slots are named slot1,slot2,slot3, etc.
However, this line gives me an error:
Players.nicknickphoenix.PlayerGui.ScreenGui.LocalScript:43: attempt to index nil with 'Value'
How should I fix it so that it will equip the tool that is supposed to be equipped?
2 Likes
08Boat
(8Boat)
August 7, 2021, 7:26pm
#2
The error suggests that ThingOccupying
is nil
.
Also, you shouldn’t equip tools on the client due to replication issues. Try using a RemoteEvent to tell the server to equip the tool.
1 Like
DevNoobxd
(DevNoobxd)
August 7, 2021, 7:33pm
#3
So, “key” is the number that the player pressed. What exactly is it? Is it a NumberValue or Enum.KeyCode or something else?
We need to know this, since the only thing the error message is saying is that "there is no ‘ThingsOccupying’ inside of ‘key’
1 Like
I used
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
to get the key
Oh yeah, forgot about that however ThingOccupying shouldn’t be nil
(As you can see, it’s a string value inside all the slots)
DevNoobxd
(DevNoobxd)
August 7, 2021, 7:43pm
#6
In this case, “key” is either something like MouseButton1 or an enum thing idk, but it does not contain ThingsOccupying for sure.
1 Like
when I do
print("slot"..key)
In the output, I get “slot1”, which is the name of the image button and slot1.ThingOccupying.Value should be the name of the tool, but instead it says “attempt to index nil with ‘Value’”
DevNoobxd
(DevNoobxd)
August 7, 2021, 7:53pm
#8
Oh I think I got it. It’s a simple logic error. This should maybe work:
player.Character.Humanoid:EquipTool(player.Backpack[("slot"..key).ThingOccupying.Value])
DevNoobxd
(DevNoobxd)
August 7, 2021, 7:53pm
#9
Replace your script’s line that caused the error with this.
Thanks, however it still did not work
DevNoobxd
(DevNoobxd)
August 7, 2021, 7:59pm
#11
Did you get any errors? If yes please tell me what the error was.
I just got the same error again
DevNoobxd
(DevNoobxd)
August 7, 2021, 8:06pm
#13
Send me a screenshot of the player’s backpact in Explorer please.
Actually I managed to fix it, I changed the line to
player.Character.Humanoid:EquipTool(player.Backpack[player.PlayerGui.ScreenGui["slot"..key].ThingOccupying.Value])
2 Likes