I am made a chat command which gives the item a player is holding but the code keeps giving this error message, I'm guessing it is the backpack but I don't know for sure how to fix it, any help? (Btw I am using a server script)
local Players = game:GetService("Players")
local Prefix = ";"
local GroupId = 5059774
function GetPlayer(targetedPlayerName)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if targetedPlayerName:lower() == player.Name:sub(1,targetedPlayerName:len()):lower() then
return player
end
end
return nil
end
Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(GroupId) >= 249 then
Player.Chatted:Connect(function(msg)
if msg:sub(1,11) == Prefix.."AddPoints " or msg:sub(1,11) == Prefix.."addpoints " then
local Amount = msg:sub(12,13) or msg.sub(12,12)
if msg:sub(15) == "me" or msg:sub(14) == "me" then
Player.leaderstats["Cafe Points"].Value = Player.leaderstats["Cafe Points"].Value + Amount
else
local Target = GetPlayer(msg:sub(15)) or GetPlayer(msg:sub(14))
Target.leaderstats["Cafe Points"].Value = Target.leaderstats["Cafe Points"].Value + Amount
end
end
if msg:sub(1,10) == Prefix.."GiveItem " or msg:sub(1,10) == Prefix.."giveitem " then
local Target = GetPlayer(msg:sub(11))
for _,v in pairs(workspace[Player.Name]:GetChildren()) do
if v:IsA("Tool") then
local Thing = v.Name
print(Thing)
local Item = game.Lighting[Thing]:Clone()
print(Item.Name)
print(Target)
print(Players[Target].Name)
end
end
end
end)
end
end)
Full error message: ServerScriptService.ServerScripts.CustomCmds:39: bad argument #2 to '?' (string expected, got Object)

6 comments
Can you give us the entire error message you're getting?
Updated
The error you're getting is on Line 39 of CustomCmds, could you indicate which line that is?
yeah we dont know what line 39 is.
Put the whole script in since I guess it would be a bit more helpful to you guys
Try removing print(Target), see what happens