I have written this code and it works perfectly
01 | local Debouunce = true |
02 | function Recieve() |
03 | if Debouunce = = true then |
04 | Debouunce = false |
05 | script.Parent.BrickColor = BrickColor.Random() |
06 | wait( 1 ) |
07 | Debouunce = true |
08 | end |
09 | end |
10 |
11 | script.Parent.ClickDetector.MouseClick:connect(Recieve) |
Can anyone show me how to access a players backpack within the script I need to give them a tool when they click the button, im not sure how to get the player that clicked! :(
Note: The code I wrote for color has nothing to do with the function i want.
Simple. You add a parameter to the function.
01 | local Debouunce = true |
02 | function Recieve(plr) -- [[ The parameter "plr" will index whatever set the function to go off..It can be named anything you want, but I don't prefer using numbers. plr is simply an example.. In this case, it's a player clicking the click detector. From here on you could add anything into the the function below using either plr.Backpackpack or plr.Character.Backpack (Not sure which, I haven't used clickdetectors in a while.]] |
03 | if Debouunce = = true then |
04 | Debouunce = false |
05 | script.Parent.BrickColor = BrickColor.Random() |
06 | wait( 1 ) |
07 | Debouunce = true |
08 | end |
09 | end |
10 |
11 | script.Parent.ClickDetector.MouseButton 1 Down:connect(Recieve) --[[I changed this to MouseButton1Down so it only works with a left click. ]] |
01 | local itemname = "Item Name Here" |
02 |
03 | local item = game.Lighting:findFirstChild( tostring (itemname)) |
04 | local trigger = script.Parent |
05 |
06 | enabled = true |
07 |
08 | function onClick(plyr) |
09 |
10 | if plyr.Backpack:findFirstChild( tostring (itemname)) = = nil and enabled = = true then |
11 |
12 | enabled = false |
13 |
14 | trigger.BrickColor = BrickColor.new( "Black" ) |
15 |
Make sure to put the tool in lighting. I hope this helps. :)