Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I need help with a hopperbin?

I want the hopperbin when selected to change the parents camera view to a part in the workspace

I'm trying to make the hopperbin once selected execute this

game.Lighting["Sword"]:Clone().Parent = game.Players.LocalPlayer.Backpack

and then remove the hopper bin from the players backpack which i'm guessing is just straight up

script.Parent:remove()

1 answer

✓ 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 -- Change this to the location of the part you want the camera at
local hopperbin = script.Parent

hopperbin.Selected:connect(function()
	camera.CameraType = "Scriptable" -- Look through the CameraType enum on the wiki for the desired effect
	camera.CoordinateFrame = CFrame.new(part.Position.X, part.Position.Y, part.Position.Z
	-- You can add more camera effects onto this as you wish, such as CameraFocus
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() -- Just for safety measures
	hopperbin:Destroy()
end)

And that's it! Your script should be ready to go.

This discussion is preserved as it was. New answers, comments, and votes are closed.