I'm trying to design a inventory system to where when I click the button it'll give me a item and if I click it again it'll delete the item from their inventory...
game.Lighting["CHANGE THIS TO TOOL NAME"]:Clone().Parent = game.Players.LocalPlayer.Backpack
In short, you can clone an item from the Lighting into the Player's backpack like-so:
game.Lighting["ThingThatYouWantToClone"]:clone().Parent = player.Backpack
If you handle the item cloning in a LocalScript then you can reference the player using game.Players.LocalPlayer
.
You can remove the item using the destroy()
method:
player.Backpack.["ThingThatYouWantToDestroy"]:destroy()
You need to be more specific when you say "Click a Button" because there are few different mediums for button clicks in Roblox! For example, you could mean clicking a Part
in the workspace, a GUI object, a SurfaceGUI,
or even a button on your keyboard!
For Part
buttons, look at ClickDetector:
http://wiki.roblox.com/index.php?title=Clickdetector
For GUIs and SurfaceGUIs, look at the ImageButton and TextButton objects:
http://wiki.roblox.com/index.php?title=Guibutton
For keys on your keyboard look at the GetMouse()
method and the KeyDown
event:
http://wiki.roblox.com/index.php?title=GetMouse_(Method) http://wiki.roblox.com/index.php?title=KeyDown_(Event)
Also, it is probably better to use either ServerStorage
or ReplicatedStorage
(rather than Lighting
) to store Instances.
Hope that helps!