Tool drop script not working correctly

I am making a tool drop script. The player pick up the tool using proximityprompt and it works fine until the player drop the tool. when player press E to drop the tool it fire an event to the server script to drop the tool but the tool still remain in character and not in workspace

dropEvent.OnServerEvent:Connect(function(plr, char, throw, cam)
	local tool = char:FindFirstChildWhichIsA("Tool")
	local hrp = char:FindFirstChild("HumanoidRootPart")
	local humanoid = char:FindFirstChild("Humanoid")
	
	if tool and hrp then
		
		local handle = tool:FindFirstChild("Handle")
		
		if handle then
			
			humanoid:UnequipTools()
			
			if throw == false then
				
				print("drop")
				
				tool.Parent = game.Workspace
				handle.CFrame = hrp.CFrame * CFrame.new(0, 0, -1)
				handle.Name = "HandleD"
				handle.Massless = false
				handle.CanCollide = true
				proximityPrompt.Enabled = true

			else
				
				print("throw")

				tool.Parent = game.Workspace
				handle.CFrame = hrp.CFrame * CFrame.new(0, 0, -1)
				handle.Name = "HandleD"
				handle.Massless = false
				handle.CanCollide = true
				proximityPrompt.Enabled = true

				local throwDirection = Vector3.new(hrp.CFrame.LookVector.X, cam.Y * 5, hrp.CFrame.LookVector.Z).Unit

				handle.AssemblyLinearVelocity = throwDirection * 50

			end
			
		end
	end
end)

2 Likes

hi can you record and send a video of the problem cuz i cant really get the problem from that one image

Hi i realized the problem the problem is that you unequip the tool, That means that the player wont hold the tool, But you have to Destory the tool, that means that the tool wont be in the players backpack, Try something like this:

copy your tool But DO NOT make it a tool just make it have a proximity prompt and scripts or something whatever you want

Screenshot 2024-12-10 141000

Then do this with the script:

dropEvent.OnServerEvent:Connect(function(plr, char, throw, cam)
	local tool = char:FindFirstChildWhichIsA("Tool")
    local toolcopy = game.ReplicatedStorage:FindFirstChild("YourToolCopy"):Clone()
	local hrp = char:FindFirstChild("HumanoidRootPart")
	local humanoid = char:FindFirstChild("Humanoid")
	
	if tool and hrp then
		
		local handle = tool:FindFirstChild("Handle")
		
		if handle then
						
			if throw == false then
				
				print("drop")
				
				toolcopy.Parent = game.Workspace
                toolcopy.CFrame = Tool.Handle
                tool:Destory()

			else
				
				print("throw")

				toolcopy.Parent = game.Workspace
				toolcopy.CFrame = hrp.CFrame * CFrame.new(0, 0, -1)

				local throwDirection = Vector3.new(hrp.CFrame.LookVector.X, cam.Y * 5, hrp.CFrame.LookVector.Z).Unit

				toolcopy.AssemblyLinearVelocity = throwDirection * 50
tool:Destory()
			end
			
		end
	end
end)

I do not want to destroy and clone another tool though. I am trying to parent the tool to workspace when drop so it can be pick up again. Everything in the script works fine except the part that the tool have to be parent to the workspace. When I drop it, it still stay inside the character

Also, I do not think it got something to do with the unequip line as I already define the tool before it

Anyways, thank for the reply. i’ll try it

Ok, after digging a bit deeper I found this post which possibly solve my problem.

I parented the tool to workspace before naming it to anything other than “Handle” which cause my character to touch it and pick it up again after dropping it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.