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)
Well you didnt specify where line 39 is so i am going off where you said it might be coming from.
I use :FindFirstChild()
instead of doing what you are doing so this is how i would do what you are doing.
if msg:sub(1,10) == Prefix.."GiveItem " or msg:sub(1,10) == Prefix.."giveitem " then local Target = GetPlayer(msg:sub(11)) -- I dont know what this function does so ima leave it like this for _,v in pairs(workspace:FindFirstChild(Player.Name):GetChildren()) do if v:IsA("Tool") then local Thing = v.Name print(Thing) local Item = game.Lighting:WaitForChild(Thing):Clone() print(Item.Name) print(Target) print(Players:FindFirstChild(Target.Name).Name) end end
this probably wont fix this problem but i hope I helped.