Give Tool Script Help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
  • Well, I want to make it when a player has a tool out and clicks U on another player the tool goes to that player.
  1. What is the issue? Include screenshots / videos if possible!
    It just doesnt give the tool at all, with no errors…

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried to look on the Dev Hub, nothing here helps.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

CLIENT

local P = game.Players.LocalPlayer
local M = P:GetMouse()


local tool = script.Parent

local Equipped = false

tool.Equipped:Connect(function()
	Equipped = true
	P.PlayerGui.Main.F.Visible = true
end)

tool.Unequipped:Connect(function()
	Equipped = false
	P.PlayerGui.Main.F.Visible = false
end)

script.Parent.Activated:Connect(function()
	Equipped = false
	P.PlayerGui.Main.F.Visible = false
end)

M.KeyDown:Connect(function(Key)
	if string.lower(Key) == "u" and Equipped == true then
		warn(M.Target,M.Target.Parent)
		if M.Target ~= nil and M.Target:IsA("Part") and M.Target.Parent.Humanoid then
			game.ReplicatedStorage.Fldr.Giving:FireServer(P,tool.Name,M.Target.Parent)
		else
			warn("no")
		end
	end
end)

SERVER

local HttpService = game:GetService("HttpService")
local webhookUrl = ""  -- Replace with your Discord webhook URL

game.ReplicatedStorage.Fldr.Giving.OnServerEvent:Connect(function(player, tool, dude, target)
	local magnitude = (player.Character.Torso.Position - target.Torso.Position).magnitude    
	warn("target")
	if magnitude <= 8 then
		warn("started")
		if player.Character:FindFirstChild(dude) then
			warn("gave")
			player.Character.Humanoid:UnequipTools()
			local targetto = game.Players:GetPlayerFromCharacter(target)
			player.Backpack:FindFirstChild(dude):Clone().Parent = targetto.Backpack
			player.Backpack:FindFirstChild(dude):Destroy()

			-- Log the event to Discord
			--[[local logData = {
				username = "Roblox Game Logger",
				embeds = {
					{
						title = "Tool Given",
						description = string.format("%s gave a %s to %s", player.Name, tool.Name, targetto.Name),
						fields = {
							{ name = "Giver Profile", value = player:GetFullName(), inline = true },
							{ name = "Receiver Profile", value = targetto:GetFullName(), inline = true },
							{ name = "Tool", value = tool.Name, inline = true }
						},
						color = 16711680  -- Red color
					}
				}
			}

			local logDataJson = HttpService:JSONEncode(logData)
			HttpService:PostAsync(webhookUrl, logDataJson, Enum.HttpContentType.ApplicationJson)]]
		end
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

I’ve tried with debugging lines aswell, no luck.

It looks like there might be a few issues. First, double-check how you’re passing the target in the Giving event. It seems like you’re passing M.Target.Parent as target, but in the server script you’re referencing target.Torso.Position.

This might not work as expected if target is passed incorrectly or doesn’t have a Torso (like if it’s an R15 character that uses a HumanoidRootPart). Try switching target.Torso to target:FindFirstChild(“HumanoidRootPart”) to make it work for both R6 and R15 rigs. Also, make sure the tool variable passed in the FireServer matches the tool’s object, not just its name.

1 Like

I am unsure on how to do this, would you be able to show an example?