Drop tool at mouse position with maximum range

I want to make tool dropping script that will make the tool im holding to drop at mouse position with maximum drop distance instead of default fall in front of player character.

I ran into a problem with client side script, it doesnt work at all and doesnt print any error, no matter what i did to try fixing it. I also tried searching everywhere for any similar scripts, i actually did find Dropping a Tool Where the Users Mouse is but it had only had part of the script, which i couldnt get to work.

Here is an example:

ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "DropToolEvent"
remoteEvent.Parent = ReplicatedStorage

local function dropTool(player, tool)
    if tool then
        local character = player.Character
        local toolClone = tool:Clone()
        toolClone.Parent = ServerStorage
        tool.Parent = nil
        wait(0.1)
        toolClone.Parent = workspace
        toolClone.Handle.CFrame = CFrame.new(player:GetMouse().Hit.p + Vector3.new(0, 5, 0))  -- Adjust the height
    end
end

remoteEvent.OnServerEvent:Connect(function(player)
    local tool = player.Backpack:FindFirstChild(player.PlayerGui.SelectedTool.Value)
    dropTool(player, tool)
end)
Client Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("DropToolEvent")

local function dropTool()
    local toolName = game.Players.LocalPlayer.PlayerGui.SelectedTool.Value
    remoteEvent:FireServer(toolName)
end

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
    if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.R then
        dropTool()
    end
end)

Uhhh,


Did u take script from somewhere?

No, it’s just an example.

charr