Answered by
8 years ago Edited 8 years ago
You would and should use arguments for this o.o
There are different ways you can go about doing this but I am going to use classical ole if statements cause I love those, they're nice :D
Anyways...
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 | local Tool = game.ReplicatedStorage [ 'Pistol' ] |
05 | Mouse.KeyDown:connect( function (Key) |
06 | local NewKey = Key:lower() |
09 | if Player.Backpack:FindFirstChild( 'Pistol' ) = = nil then |
10 | Tool:Clone().Parent = Player.Backpack |
11 | elseif Player.Backpack:FindFirstChild( 'Pistol' ) ~ = nil then |
12 | Player.Backpack.Pistol:Destroy() |
Explanation:
The first if statement basically says if the Pistol is equal to nil (doesn't exist) then it'll put the tool (Pistol) in the players backpack. If the tool is not equal to nil('~=', is there) then it will destroy the Pistol.
Extra Info:
You should always use :Destroy()
when removing / deleting something with a script so that way it doesn't cause "zombies" in your code and hog up memory, which could cause lag if you use rusty old :remove()
in too many scripts.
This is one of the many ways you can do this but I think this is the quickest way.
I hope this works, if not let me know!