Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"bad argument #2 to '?' (string expected, got Object)"?

Asked by
BiIinear 104
4 years ago

I've been making this custom inventory, and its very close to being finished. Just one little error on line 2. Here's the script.

game.ReplicatedStorage.EquipItem.OnServerEvent:Connect(function(player, item)
    player.Character.Humanoid:EquipTool(player.Backpack[item])
end)

I've tried putting "player.Character.Humanoid:EquipTool(player.Backpack[item].Name)" but that still prints out the same error. I've asked help from my friend who knows more about RemoteEvents than me, but he was confused too. I've looked on similar errors that people had, but nothing helped. Could someone please explain this?

0
Print your item name and check it. Check to make sure that there is a child of Backpack named Bilinear. If there is not a child named Bilinear, that's your problem. You would specify the argument to the item parameter as something else. DeceptiveCaster 3761 — 4y
0
The "item" value is actually named something else than BiIinear. Not sure how it got this, but someone helped me fix it earlier. BiIinear 104 — 4y

2 answers

Log in to vote
0
Answered by
birds3345 177
4 years ago

Myself i'm not good at scripting, but I think I see the error. In your square brackets try putting "tostring", tostring will probably convert you "Item" into a string.

game.ReplicatedStorage.EquipItem.OnServerEvent:Connect(function(player, item)
    player.Character.Humanoid:EquipTool(player.Backpack[tostring(item)])
end)
0
In fact it does convert it into a string, but now its printing "BiIinear is not a valid member of Backpack" I don't even know how that happens, but there's always a solution. BiIinear 104 — 4y
Ad
Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago
Edited 4 years ago

If the item is an object it would be done like this since a string needs to be in the brackets. Putting .Name after the bracket is saying the same thing but gets the name of the item in player.Backpack.

game.ReplicatedStorage.EquipItem.OnServerEvent:Connect(function(player, item)
    player.Character.Humanoid:EquipTool(player.Backpack[item.Name])
end)
0
It prints the same error as the other answer, "BiIinear is not a valid member of Backpack" BiIinear 104 — 4y
0
Is the tool equipped when the script runs sheepposu 561 — 4y
0
No. This script makes the player equip the tool BiIinear 104 — 4y
0
Run the game and then use the explorer to check the tool in the Backpack. Check that it is there and if it is, then check it is named "Bilinear" sheepposu 561 — 4y
View all comments (7 more)
0
I run the game, I go on Current: Server to check if its there, and it is, and the items name is "Testing Item" BiIinear 104 — 4y
0
That's why. The item you are sending through the event is not in their backpack sheepposu 561 — 4y
0
But that makes no sense... the "item" variable sent through the event fire is "local item = script.Parent.ItemNameValue.Value" and ItemNameValue is the items name in the backpack, I have no idea whats going on BiIinear 104 — 4y
0
How is the value of ItemNameValue decided. As in how does the script give it it's value sheepposu 561 — 4y
0
So you click an item in workspace, a tool that is a copy of the item gets cloned from Lighting into your Backpack, the tool has a localscript, and that localscript locates ItemNameValue and its value is determined by setting it to the tools name BiIinear 104 — 4y
0
Then it should work. I can't think of a reason why it wouldn't work sheepposu 561 — 4y
0
post a new question about this problem with the details we were talking about here sheepposu 561 — 4y

Answer this question