Basic Click Detectors and Tools

Hey there! So I just have 2 quick question.

The first one is whats the most efficient way to use click detectors but make it so that it only lets them when they have a Tool Equipped.

The second one is How would I go about equipping backpacks on players backs?

So basically I’ll make a shop system for them to buy better backpacks but I’m not sure how to position them on their back…

3 Likes

Theres 3 ways to do the First Question…

1:

Have the tool check to see if the mouse’s Target has a Click Detector in it… If so, then disable it locally until the target is on something else…

2:

Have the script that controls the click detector make sure the tool is equipped before it continues on…

3:

Do as your previous post said, make custom click detectors. Once the player clicks, get the target of the mouse and if it is a certain part that needs one, just continue on and execute the code needed…

For your second question… Can you elaborate, I don’t quite understand… sorry.

1 Like

For the backpack script, you would have a value in the player of the backpack they have currently equipped. You then would have a folder of backpacks they own, they can equip backpacks they only own. When the player joins, the value(s) will load using DataStore. Once the player is in the server, you would’ve had backpacks in serverstorage or replicatedstorage. The backpacks would have a part on the back, and you would make sure the part is facing the torso. You would weld the part to the back of the player’s HumanoidRootPart, and there you go, you got a backpack. For the shop you would fire the server with the backpack name, there would be a module list of the backpack prices, and the server would go off the module ( in example; the module contains the backpack(s’) names and values what I mean by values is maxstorage and anything else you need ). Everything would load according to that module. The indicator on the back is a surface GUI with a textlabel. The TextLabel would display a value inside the player, Value1 for example is blocks, in a mining game is how many blocks they mined and are in the backpack, Value2 is how much the backpack can store, so the SurfaceGui would display the text as Value1…"/"…Value2 , and if needed you could do math.floor() to get rid of the decimals. The backpack also can’t be anchored, and you would weld the backpack together ( make sure it isn’t collideable too ). If a player wants to equip a backpack, that they own, then it would fire the server with the backpack name, the server would check if the player owns the backpack , if they do, and it wasn’t an exploiter firing, then it checks what the currentbackpack value is, and finds it inside the player, and then destroys it, and clones and welds the new backpack! You would also need a script (server side) constantly checking if Value1’s Value is higher than Value2’s, this is to make sure it doesn’t exceed the maximum limit. I think thats all for a backpack, lets answer the first question now. What you would do is detect if the tool is equipped , once the player clicks the detector, it gets the player from the click, and checks if the tool is a valid member of backpack. If it isn’t, you check if it is in the player’s Character, if it is there then the click will continue, the reason why we check if it is in the Character, is because when a tool is equipped it changes its parent to the player’s Character. Hope I explained everything well!

2 Likes

Alrighty Thank you 12904! I’ll try it out

Wow! You went into so much detail. Surprisingly I seem to have understood most of it! I’ve been watching you on YouTube for a while. Love those scripting tutorials very helpful and great content over all. I’ll be following what you wrote step by step Thanks again. Kind Regards TheTimeDefender.

No problem, I am glad I could help you. I make YouTube videos to help the community! Have a good night, and I wish you luck with the code. :smiley:

Will do Thanks again!..

1 Like