Dropping a Tool Where the Users Mouse is

Using bool values are unnecessary to see if a tool is equipped or not.
Unless you’re using your own tool system.

But for Roblox’s tools, when a tool is equipped it will be parented to the player character/model
When a tool is unequipped it will be parented to the player’s backpack

And since you want to drop the player’s currently equipped tool.
You may shorten the code to something like this instead:

local dropEvent = game.ReplicatedStorage.dropEvent

dropEvent.OnServerEvent:Connect(function(plr, mousePos)
	local limit = 10 -- You can change it to your liking.
	
    --Check for the current equipped tool
	local character = plr.Character
	local tool = character:FindFirstChildOfClass("Tool")
	if not tool then return end
	
    --Check distance
	local checkDistance = plr:DistanceFromCharacter(mousePos)
	if checkDistance > limit then return end
	
    --Drop tool
	tool.Parent = workspace
	tool.Handle.Position = mousePos + Vector3.new(0,1,0)

end)

Yeah, I’ve been scripting for about half a year and know a lot of basic stuff. Stuff like ipairs and functions still get me confused though, so I’ll definitely be looking more into those.

This works great aswell. Good to know that the tool changes parent.

1 Like

Ipairs is almost the same as pairs, i cant really explain it.

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