Recently (As of 21/04/2023) I came across and issue that probably nobody had, A proper drop script. One that I mean actually drops an item in-front of you and doesn’t do this.
This irritated me, because I wanted to drop an item in a small confined area but I couldn’t as my drop would just go through the roof and the walls. So I spent hours searching for a solution and I couldn’t find one, Until I kept using trial and error to finally beat this bug.
Project Setup:
-
Create LocalScript In “StarterCharacterScripts”. Name it whatever you want.
-
Paste this code into your script
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Dropped") -- Wait for RemoteEvent to Load
local player = game.Players.LocalPlayer -- Get local player
UserInputService.InputBegan:Connect(function(input, player) -- InputService
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Q then -- When Q is pressed do this
remoteEvent:FireServer() -- Fire Remote Event
end
end
end)
-
Next you must locate to “Replicated Storage”. Now create a “RemoteEvent” and called it “Dropped”. Now create a folder in “Replicated Storage” called “Items”, Place every single one of your items inside this folder for these scripts to work.
-
Now make a “Script” Inside of “ServerScriptService”. Name it whatever you want.
Then paste this one of two these code boxes provided inside of the script.
SOLUTION 1
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local runService = game:GetService("RunService")
local remoteEvent = ReplicatedStorage:WaitForChild("Dropped")
remoteEvent.OnServerEvent:Connect(function(player)
local humanoid = player.Character:WaitForChild("HumanoidRootPart") -- Wait for player humanoid to load
if humanoid then
local cast = workspace:Raycast(humanoid.Position, humanoid.CFrame.LookVector * (4)) --Raycast 4 studs away from players lookVector
if cast ~= nil then -- If the cast hit something
local items = game.ReplicatedStorage.Items -- Get Items Folder
local item = player.Character:FindFirstChildWhichIsA("Tool") -- Get equipped player tool
if item then -- Make sure an Item is equipped so no errors are thrown
local tool = item:FindFirstChild("Handle") -- Get the handle of this tool
item.Parent = game.workspace -- Parent to workspace
item.Handle.CFrame = CFrame.new(cast.Position) -- Set the CFrame of the part to this raycast hit position
else
return -- No Item Equipped
end
else -- If Raycast Hit Nothing
local items = game.ReplicatedStorage.Items -- Get Items Folder
local item = player.Character:FindFirstChildWhichIsA("Tool")-- Get equipped player tool
if item then -- Make sure an Item is equipped so no errors are thrown
local tool = item:FindFirstChild("Handle") -- Get the handle of this tool
item.Parent = game.workspace -- Parent to workspace
item.Handle.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-4) -- Set The CFrame position to infront of the player
else
return -- No Item Equipped
end
end
end
end)
- Thats it, your drop system should now work.
NOTE: If for whatever reason solution 1 doesn’t work with your items, you can use solution 2, and vice versa. If you have any improvements etc. Feel free to comment them and I can repost this with an improved version. A big thanks to @lAmTheGovernment for the first solution and @Bubblebuddy200 for the raycast implementation. Lots of credit to them for the help.