I’ve been working for a drawer system in my game, I’m pretty confident that I can do it, but I have stumbled unto some issues :
As my drawer system is in a script, and each and every drawer haves that script, if I would ever want to change it, it’ll make me forced to change EVERY drawer’s script.
My idea was to use a bindable event, but considering the drawer system is on server side, this mean that multiple players can just spam the drawers, and wouldn’t that overwhelm the bindable event?
Also, another reason I wanted to use a bindable event is because I want to use tweening for the animation, but considering I don’t know a lot on optimization, I don’t know if a lot of tweening and localizing it would cause an issue.
I’ve tried to find info about bindable event overwhelming and how I would modify all the scripts more easily but I just can’t find something to help me. Thanks!
Use collection service and proximitypromptservice! basically, use proximitypromptservice (on the client, you might need to send a remote event to the server, but i’m uncertain if you can do it on the server, but i’d imagine you’d need to do it on the client), with proximitypromptservice, you can do PromptTriggered, Now we use collection service to see if the parent of the proximity prompt has the tag (you might need to add more parents, i’m uncertain on the hierarchy of your draw model. might look a little like this:
local CollectionService = game:GetService("CollectionService")
game.ProximityPromptService.PromptTriggered:Connect(function(Prompt, PlayerWhoTriggered)
if CollectionService:HasTag(Prompt.Parent, "Name This your tag name") then
print("Drawed")
end
end)
(you will need to add the tag to every single drawer, but you can multiselect so it’s not that annoying)
Does proximitypromptservice detect every single prompt that happens, even if it’s not for the drawer? If I understand right, we detect if ANY prompt was triggered, we check if the tag is from a drawer, find it and open it? But would this mean I need to make a new tag for each drawer?
Yeah it does, thats why you add a tag to the drawer so that your script only affects the drawers. Adding a tag to every drawer is a wholeeee lot more efficient than having a separate script in every single drawer. Makes the code very easily editable as well.
if all the drawers do the same thing like moving in and out then you can use the same tag on your drawers. Let’s say some drawers have a coin within them, then you’ll create a new tag for this special type of drawer
I think I understand what issue you are facing. If you are trying to get every drawer, regardless of what it has inside it, you will need to name them “Drawer” then use :GetDescendents() to check if that instance is named “Drawer”
for _, instance in workspace:GetDescendents() do
if instance.Name == "Drawer" then
instance.ProximityPrompt:Connect(function)
If you connect a function at the end of that you can have it handle all the logic, calculations, and tweening, and adding a new drawer is as simple as just calling something else “Drawer”.
@Gloriusjackal this is another way to get all the drawers that way you can keep all the code in one script. I favor the tag system more because that way you wont need to keep all the drawers under a specific name in a specific file location.
You wouldnt make a different tag for every drawer because then if you wanted it to connect the code to each drawer you would have to reference each and every tag. You can put multiple objects under the same tag, that way they will all behave the same way when you connect the code to the tag.
Go watch a youtube video on roblox tags to learn more, especially if you’re a more visual learner
Hi! Both codes work the same way, collection service might be slightly more optimized since it specifically looks for tags rather than names in descendants.
At the same time I, for one time executed codes, I prefer to name Drawer models “Drawer” and use a table to save all the instances to then apply whatever logic I want to them as memorizing tags and having multiple classes of tags such as doors and windows might get confusing if you have a lot of them.
Its just a matter of preference, and at least with what I read through his prompt and the replies it seems he wants an alternative way of doing it without tags, and I gave him that option (since you tend to name model instances anyways)
Nothing wrong with either way just a matter of preference
Thank you so much! This worked, but I have another question about how I made the drawer system : considering it’s not for each and individual drawer the script, the only way to save the previous position of a drawer and if it was opened or not individually for each one was to use attributes
(I can’t use a variable because multiple drawer’s variable would just overlap and I think storing it in an array/table or whatever would just make this more complicated)
ok i think there is a few ways of doing this, 1 would be like having a part in every drawer that position never changes, and it kinda acts like an origin point, and if the drawer is in that, then you know whether to open/close it
i’ve been up for like 20 hours so im really sorry if this isn’t comprehensive , i hope that i got it right tho lmaoaoao; also since it worked you (if you want) should probably mark it as solved!!