Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help with a hopperbin?

Asked by
Prioxis 673 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

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.

Ad

Answer this question