So I have a hard time with coding, like I know the words, I just don't know the structure. If someone could help me structure this better I would appreciate it.
script.Parent.Selected:connect(function(k) m.KeyDown:connect(function(k) print(k) if k=="q" then local tool=script.parent tool.Equipped:connect(function(KeyDown) m.KeyDown:connect(function(k) end) end) end) end) script.Parent.Selected:connect(function() end)
If you don't quite understand the Structure of the script, i'll show you.
local tool=script.Parent
A variable is a Title that holds a value
, the Variable shown above is currently holding script.Parent
as it's value. Next we need an Function
, some functions can be already defined, and some can be custom.
-- predefined function object.Touched:connect(function(parameter) return parameter end) -- undefined function local ABC=function(a,b,c) -- a,b,c as the function's parameter return print(a,b,c) end --(parameters are variables kept in a function)
But if you want a defined function then we use events
, What is an event? An event is an Object that connects to a user-defined function(listeners), when the certain event ever happens, the Event fires. In this case an KeyDown
event.
local tool -- define tool local player=game.Players.LocalPlayer local character=player.Character local humanoid=character:WaitForChild("Humanoid") player:GetMouse().KeyDown:connect(function( key ) if key==" q " then humanoid:EquipTool(tool) end end)
If by structure you mean tabbing and where to put things, I cleaned this up for you:
tool = script.Parent --Ideally, you want to declare some variables in the beginning of the script. script.Parent.Selected:connect(function(mouse) --The "Selected" event passes the mouse as an argument to its connected function. mouse.KeyDown:connect(function(key) if key == "q" then --You could also write these 3 commands out on 1 line, since they're so short. print(key) end end) --Closing the KeyDown function end) --Closing the Selected function