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

Help with "onClicked" function?

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

2 answers

✓ Accepted answer

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.

Weapon = Lighting.Weapon
script.Parent.MouseClick:connect(function Clicked(Player)
	Weapon:clone().Parent = Player.Backpack
end)

--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.

1 comment

0

Still having trouble, can you elaborate a little bit more on the process?

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.

1 comment

0

And I apologize for my ignorance, if you think that.

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