I’m making a handto command with the BAE plugins feature where you can essentially create custom commands with the module. My command is supposed to take the tool that you have equipped and place it in your target’s backpack. For whatever reason, it doesn’t work and no error is returned due to BAE’s error handling which is literally just this:
Any help would be appreciated!
Code:
local pluginName = 'handto'
local pluginPrefix = Prefix
local pluginLevel = 0.5
local pluginUsage = "<User>" -- leave blank if the command has no arguments
local pluginDescription = "Hand off that food item you just made fresh off the grill!"
-- Example Plugin Function --
local function pluginFunction(Args) -- keep the name of the function as "pluginFunction"
local function FindPlayer(String)
for i,v in pairs(game:GetService("Players"):GetChildren()) do
if (string.sub(string.lower(v.Name),1,string.len(String))) == string.lower(String) then
return v
end
end
end
if not FindPlayer(Args[3]) then return end
FindPlayer(Args[1]).Character:FindFirstChildWhichIsA("Tool").Parent = FindPlayer(Args[3]).Backpack
end
local function pluginFunction(Args)
local function FindPlayer(String)
for i, v in pairs(game:GetService("Players"):GetChildren()) do
if (string.sub(string.lower(v.Name), 1, string.len(String))) == string.lower(String) then
return v
end
end
end
local targetPlayer = FindPlayer(Args[1])
if not targetPlayer then
return "Player not found!" -- Informative error message
end
local tool = script.Parent.Parent:FindFirstChildWhichIsA("Tool")
if not tool then
return "You don't seem to be holding a tool!" -- Informative error message
end
-- Attempt to transfer the tool (may not work due to security restrictions)
tool.Parent = targetPlayer.Backpack
return "Attempt made to hand the tool to " .. targetPlayer.Name .. "."
end
I’m still getting the function error from BAE. Nothing is printing, just the same old error from BAE that I included in my original post.
You mentioned that it may possibly be a result of security restrictions. How can I go about making it so that these restrictions don’t impede on the function I’m trying to get?
local function pluginFunction(Args)
local function FindPlayer(String)
for _, player in ipairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == string.lower(String) then
return player
end
end
end
local targetPlayer = FindPlayer(Args[1])
if not targetPlayer then
return "Player not found!"
end
local tool = game.Players:GetPlayerFromCharacter(script.Parent.Parent).Character:FindFirstChildWhichIsA("Tool")
if not tool then
return "You don't seem to be holding a tool!"
end
tool.Parent = targetPlayer.Backpack
return "Attempt made to hand the tool to " .. targetPlayer.Name .. "."
end
Basic Admin Essentials comes with a premade plugin called pluginExample which you should use their premade system for getting players, but I’m assuming maybe you’re doing a different script do it can pick one player rather than having it do others, or all, or putting commas to put certain group of players like ‘player1,player2,etc’.
I can’t tell what you’re having issues with, finding the player or actually handing the item to the player.
If you can’t find the player, then like I mentioned before you can use the premade one, and if you’d prefer for one player to be allowed, then before the loop function create a variable and set the value to 0, then while its looping and finds a player, increase the variable by 1. Then do 'if variable > 0 then (put what you want it to do if its multiple players) else put the handto function end
The premade system uses BAE’s returnplayers function which checks for ‘others’, ‘all’, or if they decided to split to do a certain group of players, or just filters for that one player, and it saves you the time of having to make your own if you’re having issues with that.
If you’re having issues with handing it to the player, just do this:
if Player.Character ~= nil then
if Player.Character:FindFirstChildWhichIsA(‘Tool’) then
Player.Character:FindFirstChildWhichIsA(‘Tool’).Parent = thetargettedplayer.Backpack
end
end