How do I code a script so that if I click a weapon that I put in the workspace as a model it puts it into your backpack? I have the weapon with all the scripts in the lighting but all I have with my script currently is just the code below. Help?
local m = game.Workspace.Musket function onClicked(mouse) game.Workspace.Musket end
Firstly you have to have a ClickDetector in the weapon model. You also have to have a copy of the Weapon as a tool in Lighting.
1 | Weapon = Lighting.Weapon |
2 | script.Parent.MouseClick:connect( function Clicked(Player) |
3 | Weapon:clone().Parent = Player.Backpack |
4 | end ) |
5 |
6 | --You'd put this under ClickDetector. |
When creating a function, it doesn't do anything, until you make a connection line/event listener. In this case the event listener is script.Parent.MouseClick:connect
.
Firstly, the whole thing should be a Tool, with a Handle. For more information on scripting with tools, visit PeasFactory on YouTube on how to script with tools. He will explain to you what Tools are and what to script.