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

ClickDetector help. I need help accessing the player who clicked. ?

Asked by 9 years ago

I have written this code and it works perfectly

01local Debouunce = true
02function Recieve()
03    if Debouunce == true then
04        Debouunce = false  
05        script.Parent.BrickColor = BrickColor.Random()
06        wait(1)
07        Debouunce = true
08    end
09end
10 
11script.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.

3 answers

Log in to vote
0
Answered by 9 years ago

illuminatti

Ad
Log in to vote
0
Answered by 9 years ago

Simple. You add a parameter to the function.

01local Debouunce = true
02function 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
09end
10 
11script.Parent.ClickDetector.MouseButton1Down:connect(Recieve) --[[I changed this to MouseButton1Down so it only works with a left click. ]]
0
Would i need a local script inside the part then? To acess the player ConnorXV 5 — 9y
Log in to vote
0
Answered by
ImfaoXD 158
9 years ago
01local itemname = "Item Name Here"
02 
03local item = game.Lighting:findFirstChild(tostring(itemname))
04local trigger = script.Parent
05 
06enabled = true
07 
08function 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 
View all 27 lines...

Make sure to put the tool in lighting. I hope this helps. :)

0
does this need to be in a local script or a normal script ConnorXV 5 — 9y
0
Nope, just insert it into a normal script and put it inside to a brick. Also insert an object called "ClickDetector" into the brick and you're good to go. ImfaoXD 158 — 9y

Answer this question