✓ Accepted answer
First of all, every script should be in a Local Script in order to function properly.
For the first part of your question, you can manipulate the camera by getting the player's camera with CurrentCamera and manipulate it with some camera manipulation properties:
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local part = game.Workspace.Part
local hopperbin = script.Parent
hopperbin.Selected:connect(function()
camera.CameraType = "Scriptable"
camera.CoordinateFrame = CFrame.new(part.Position.X, part.Position.Y, part.Position.Z
end)
Now we will make it so that it clones the sword into the backpack:
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local part = game.Workspace.Part
local hopperbin = script.Parent
hopperbin.Selected:connect(function()
camera.CameraType = "Scriptable"
camera.CoordinateFrame = CFrame.new(part.Position.X, part.Position.Y, part.Position.Z
game.Lighting:findFirstChild("Sword"):Clone().Parent = player.Backpack
end)
Lastly, we'll make the script remove the hopperbin:
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local part = game.Workspace.Part
local hopperbin = script.Parent
hopperbin.Selected:connect(function()
camera.CameraType = "Scriptable"
camera.CoordinateFrame = CFrame.new(part.Position.X, part.Position.Y, part.Position.Z
game.Lighting:findFirstChild("Sword"):Clone().Parent = player.Backpack
wait()
hopperbin:Destroy()
end)
And that's it! Your script should be ready to go.