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

Getting Weapons from lighting?

Asked by
smd34 30
9 years ago

I want to make a custom class gui. In this gui, I wan to be able to select a weapon and be able to remove it from backpack it when I click on a text button (text will say Remove). How would I retrieve the weapon from the lighting ****WHEN I CLICK A TEXT BUTTON AND THEN REMOVE IT ( rmove as in like to remove it from backpack.)WHEN PRESSING ANOTHER TEXT BUTTON****???? The weapons are tools and I know i have to have tools in lighting. If answered I will be very grateful.

3 answers

Log in to vote
0
Answered by 9 years ago

You should not be storing your weapons in the lighting see Replicated Storage

You should just be able to clone the tool Click here

You can delete the tool using this method Click here

Ad
Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago

Well firstly, I couldn't exactly understand what you were trying to ask here due to the grammar used in the post, but I may have a rough idea. Since you did not post a script of you attempting I'm not going to make the script for you, but I will tell you how it works.

Assuming you have the Gui already made for the guns what you want to do is check that the gun/weapon is in the lighting using an if statement, then you want to clone it and parent it to the player's backpack (hopefully you know how to find the player) Then once you have that done to remove the gun/weapon all you have to do is use an if statement to check if the gun is in that person's backpack and simply use Player.Backpack.Weapon:Destroy()

If you do not know how to do some of these things I recommend looking on the wiki (http://wiki.roblox.com)

Some Wiki stuff:

Cloning

Destroying + Parenting Example

0
I'm glad I spent so much time on an answer that would make sense to him and some guy makes an answer in 3 lines and it's accepted, but mk, as long as he understands xD Ryzox 220 — 9y
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

First of all; you shouldn't use Lighting for storing objects. You should use ReplicatedStorage or ServerStorage (if you're using a LocalScript, ReplicatedStorage).


Your question isn't very clear (spend more time editing, and no need to yell), but as I understand it two things have to happen:

  • A way to give specific tools to player
  • A way to clear out every tool that was given

Here's one option:

local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")

local tools = {}
-- A list of all the tools this player has been given

function giveTool( name )
    -- Looks in game.ReplicatedStorage.Tools for something
    -- named "name" and gives to the local player
    local tool = game.ReplicatedStorage.Tools[ name ]:Clone()
    -- A copy of it
    tool.Parent = backpack -- Put it in their backpack
    table.insert(tools, tool)
end

We are keeping track of tools so that we can make the clear function very easily:

function clearGivenTools()
    for _, tool in pairs(tools) do
        tool:Destroy()
    end
    tools = {}
end

Now you just have call these functions on buttons.

To change to a "class" (a group of tools) you would first clear and then add several tools:

function changeToMedic()
    clearGivenTools()
    giveTool( "Syringe Gun" )
    giveTool( "Ubersaw" )
end

function changeToSpy()
    clearGivenTools()
    giveTool( "Cloak and Dagger" )
    giveTool( "Butterfly Knife" )
end

Answer this question