Tool not cloning to backpack

No errors are recieved and the item is not cloned to the player backpack.

Pickup item script:

local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local maxPickupDistance = 30
PickupItem.OnServerEvent:Connect(function(player, item)
	
	local distanceFromItem = player:DistanceFromCharacter(item.Handle.Position)
	if distanceFromItem < maxPickupDistance then
		local toolclone = item:Clone()
		toolclone:Clone()
		toolclone.Handle.Anchored = false
		toolclone = player.Backpack
	end
end)

Script firing event:

local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local UIS = game:GetService("UserInputService")

local pickupKey = "E"

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local playerGui = player:WaitForChild("PlayerGui")
local ToolPickupGUI = playerGui:WaitForChild("ToolPickupGUI")

UIS.InputChanged:Connect(function()
	if mouse.Target then
		if mouse.Target.Parent:IsA("Tool") then
			ToolPickupGUI.Enabled = true
			playerGui.ToolPickupGUI.Adornee = mouse.Target
		else
			ToolPickupGUI.Enabled = false
			playerGui.ToolPickupGUI.Adornee = nil
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode[pickupKey] then
		if mouse.Target then
			if mouse.Target.Parent:IsA("Tool") then
				local item = mouse.Target.Parent
				if item then
					PickupItem:FireServer(item)
				end
			end
		end
	end
end)
1 Like

the tool isnt cloning as the RemoteEvent is never fired. Put
PickupItem:FireServer(<Define The Tool To Clone Here>) on a line where you want the client to tell the server to give the localplayer said tool

Would I add that into the script thats firing the RemoteEvent?

yes. and if im correct

those lines of code are for the tool to pick up i believe i would recommend changing it to

			ToolPickupGUI.Enabled = true
			playerGui.ToolPickupGUI.Adornee = mouse.Target
			PickupItem:FireServer(<Define The Tool To Clone Here>)

if im correct

and then delete the other cloning events in the other script?

Oh i didnt see the other cloning events let me take a look at it

1 Like

Not sure if this is the issue but why are you cloneing it once then again? Makes no sense when you could just do the things to toolclone not cloneing it twice.

I saw that and decided to remove it.

Also just so you know players can walk on a tool on the ground to pick it up. I would recommend having all tools in lets say ServerStorage in a folder called Tools and having the visible tools on the group just models of the tools and running your script from there

if mouse.Target.Parent:IsA("Tool") then
to
if mouse.Target.Parent:IsA("Model")
and please do send any errors that show up in output

2 Likes

Also I think on the end part where you did “toolclone = player.Backpack” you need to make sure to do toolclone.Parent = player.Backpack

I found a way to disable the walking over tools thing and was able to fix it. I also want the tools in the workspace.

By doing this, I recieve an error stating that you’re unable to clone the workspace.

still

as exploiters could fire the RemoteEvent making it possible for them to receive a tool that could be no where near them

I’m not too worried about that as the items are cereal boxes and merchandise for a store.

But you don’t clone to the workspace in these scripts do u? Not sure why you get that error but I belive that is why it will not clone to the backack.

Here are my scripts currently:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local maxPickupDistance = 30
PickupItem.OnServerEvent:Connect(function(player, item)
	
	local distanceFromItem = player:DistanceFromCharacter(item.Handle.Position)
	if distanceFromItem < maxPickupDistance then
		local toolclone = item:Clone()
		toolclone.Handle.Anchored = false
		toolclone = player.Backpack
	end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local UIS = game:GetService("UserInputService")

local pickupKey = "E"

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local playerGui = player:WaitForChild("PlayerGui")
local ToolPickupGUI = playerGui:WaitForChild("ToolPickupGUI")

UIS.InputChanged:Connect(function()
	if mouse.Target then
		if mouse.Target.Parent:IsA("Tool") then
			ToolPickupGUI.Enabled = true
			playerGui.ToolPickupGUI.Adornee = mouse.Target
		else
			ToolPickupGUI.Enabled = false
			playerGui.ToolPickupGUI.Adornee = nil
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode[pickupKey] then
		if mouse.Target then
			if mouse.Target.Parent:IsA("Tool") then
				local item = mouse.Target.Parent
				if item then
					PickupItem:FireServer(item)
				end
			end
		end
	end
end)
local player = game.Players.LocalPlayer

Is this script (the bottom script) in a server or local script?

The bottom script is a LocalScript.

I’ll actually try this right now, I’ll let you know the outcome of this.

note localscripts CANT see server storage. Besure to have a way the server will know which tool the client is telling it to clone