Hi! I am currently working on a game and I came across an issue that I haven’t been able to solve.
I made a Hand-To command using Basic Admin Essentials plugins, and it works as expected. The issue I have is that the remote function I am using for it isn’t changing the parent of the tool from the player that sends to the one that receives.
I have tried using remote events instead, checking if the tool exists, changing the way I referenced the receiver, but nothing has worked. I also looked for help in the devforum… and I’m not that experienced with remote functions and events.
This is my script so far
local TargetTool = Player.Character:FindFirstChildWhichIsA(“Tool”)
function RemoteFunction.OnServerInvoke()
TargetTool.Parent = b:WaitForChild(“Backpack”)
end
In the script, b is the receiver, Player is the sender. I compare the TargetTool variable to nil before going to the function, so the tool exists there.
That’s not how remote functions work, you should pass player2 as an argument from a client script(LocalScript that handles the tool) to a server script using the remote(RemoteFunction:InvokeServer(player2)). Then pick it up inside a server script to actually parent the tool.
Server script code:
local RemoteFunction = game.ReplicatedStorage.RemoteFunction --path to function
RemoteFunction.OnServerInvoke = function(player, player2)
local TargetTool = player.Character:FindFirstChildWhichIsA("Tool")
TargetTool.Parent = player2:WaitForChild("Backpack")
end
It depends on if the module script function is being called from the client or the server and how it gets called. I suggest you check Remote Functions.
So I was checking that article and other devforum examples about it but I can’t understand the issue, and the module script function is being returned to a server script
local TargetTool = Player.Character:FindFirstChildWhichIsA(“Tool”)
if TargetTool == nil then
remoteEvent:FireClient(Player,‘Message’,’Error’,’Make sure you have a tool equipped.’)
elseif TargetTool then
local RemoteFunction = game.ReplicatedStorage.GiveTool
RemoteFunction.OnServerInvoke = function(Player, b)
TargetTool.Parent = b:WaitForChild(“Backpack”)
end
end
RemoteFunction.OnServerInvoke = function(Player, b)
local TargetTool = Player.Character:FindFirstChildWhichIsA("Tool")
if TargetTool then
TargetTool.Parent = b:WaitForChild("Backpack")
else
remoteEvent:FireClient(Player,"Message","Error", "Make sure you have a tool equipped.")
end
end
This is just an addition or a reccomendation, but if you dont need to return anything there isnt much of a reason to be using remotefunctions. RemoteEvents will be more suited for this application.
I was able to fix the problem by using BAE included remote event and plugin documentation. Passing in three arguments, the sender, receiver and tool. Everything inside the module script.