#Why is this line of code not giving me a Rocket Launcher when I click it?

1 messages · Page 1 of 1 (latest)

naive umbra
#

local Rocket = game.ServerStorage.RocketLauncher
script.Parent.ClickDetector.MouseClick:Connect(Function(click))
local RocketClone = Rocket:Clone()
local Player = script.Parent.Parent.Parent.Parent
if click then RocketClone.Parent = Player.Backpack
end

the last time i asked this i was told to learn the basics. i thought i had? anyways PLEASE HELP I'M SO CONFUSED.

cedar vortex
#

when you connect MouseClick to a function just put the code inside the function that you want to run when you click the part.

So you would do

local Rocket=game.ServerStorage.RocketLauncher
script.Parent.ClickDetector.MouseClick:Connect(function()
local RocketClone = Rocket:Clone()
local Player = script.Parent.Parent.Parent.Parent
RocketClone.Parent = Player.Backpack
end)

#

you dont have to do if click then

#

let me know if that works

naive umbra
cedar vortex
#

ok, where is the script located. That probably means that the Player is not located at script.Parent.Parent.Parent.Parent

naive umbra
cedar vortex
#

MouseClick also gives you a variable that contains the player who clicked

forest beacon
#

its better if you use a remote function for this

naive umbra
#

i was gonna have like a class system and you chose what class you wanted when you opened the game, but that was too hard so i['ve just programmed it to a part

forest beacon
#

or is it a remote event i forgot

cedar vortex
#

local Rocket=game.ServerStorage.RocketLauncher
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
local RocketClone = Rocket:Clone()
RocketClone.Parent = Player.Backpack
end)

naive umbra
#

im gonna be so honest with you i have not the slightest clue how to code

cedar vortex
#

you can remove the "local Player = ..." and use the Player inside the function arguments

naive umbra
#

tysm dude

forest beacon
#

@naive umbra go learn remote events and functions itll be better

naive umbra
#

also

#

will this work if i program it to give a different item>

cedar vortex
#

It should

naive umbra
#

like a bomb for example

#

kk tysm dude

cedar vortex
#

Yeah just change
"game.ServerStorage.RocketLauncher"
to like
"game.ServerStorage.Bomb"

#

just replace "Bomb" with the name of the tool

naive umbra
#

alright.

#

is there any advice you can give?

#

because i created that first line of code with some assistance but i did fix it a bit

cedar vortex
#

just make sure you type the name exactly and dont do any spaces or special characters and it should work

naive umbra
#

alr

#

thanks dude