So I was making admin commands and I was making a bring command. To explain it, it just basically teleports the specified player to admin's location.
Now when I made the code, I got this error: Workspace.AdminCommands:15: attempt to index field 'Character' (a nil value)
Here is my code:
local admins = {'FE3_MapTester', 'Player1'} -- Player1 is for experiments
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
for i, admin in pairs(admins) do
if plr.Name == admin then
-- // Commands
if msg:sub(1, 7) == ';bring ' then
local target = game.Players:FindFirstChild(msg:sub(8))
if target then
local char = target.Character
if char then
local root = char.HumanoidRootPart
if root then
local adminRoot = admin.Character.HumanoidRootPart
local adminPosX = adminRoot.Position.X
local adminPosY = adminRoot.Position.Y
local adminPosZ = adminRoot.Position.Z
local newPos = CFrame.new(adminPosX - 2, adminPosY, adminPosZ)
root.CFrame = newPos
end
end
end
end
end
end
end)
end)
Error line is 15.
Thanks!

6 comments
What does the error message say?
Read more carefully. I mentioned it
Oh sorry somehow I didn't see it
Line 21 is an end keyword...
sorry let me edit it
"admin" isn't an actual player, it's just a string. Just replace admin.Character.HumanoidRootPart on lines 15-18 to plr.Character.HumanoidRootPart