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

Help with "onClicked" function?

Asked by
painzx3 43
10 years ago

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

Log in to vote
1
Answered by 10 years ago

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.

0
Still having trouble, can you elaborate a little bit more on the process? painzx3 43 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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.

0
And I apologize for my ignorance, if you think that. fahmisack123 385 — 10y

Answer this question