Needing help in creating a script that triggers when 3 players holding tools are within radius

Is anyone able to help with creating a script that triggers when 3 players equipping specific tools are within a certain radius of each other?

TL;DR a script that works similar to the Bird Up event in Item Asylum.

Havent played asylum, but here’s a theoretical roadmap that could accomplish your goal with some pros and cons at the end:


Setup

  • Script in the ServerScriptService
  • LocalScript in the Tool object
  • RemoteEvent in the ReplicatedStorage

Scripting

Local Script

Setup Tool.Equipped and Tool.Unequipped events which both call RemoteEvent:FireServer()

Server Script

Setup RemoteEvent.OnServerEvent to call a function which:

  1. Checks for an instance tag with the players name via the HasTag() method
  • HasTag() returns false: add a tag with the players name using AddTag. Also need to setup a Humanoid.Died event that removes the tag if its present to prevent tags from accumulating if players die while holdin the tool and breaking the whole system.
  • HasTag() returns true: remove the tag via RemoveTag()
  1. Gets all other instance tags on the server script via Tags = script:GetTags()
  • If #Tags >= 3 then check your distance from the other characters using the Tool by finding their Player object via the Tags table which has their name in it and then using DistanceFromCharacter() to check distances. If all distances are within the limit then
    > Do whatever it is that happens when the conditions are met.
    Otherwise:
    > Do nothing

  • If #Tags < 3 then do nothing


Considerations

How it works

So basically whats going on is the script is keeping track of who has this tool equipped by adding their names as an instance tag to the script object. When you equip the tool, the tag doesnt exist yet, therefore HasTag returns false, and adds your name as a tag. When you unequip the tool, HasTag will return true and remove your tag. Regardless of the action, next we get an updated table of the current tags and if theres at least three users then we check the distance between their characters. If this distance is within limit, then do whatever special thing it is thats supposed to happen - Pull_The_Lever_Kronk.exe

Pros

  • Sanity checks performed on server,
  • No arguments are passed to the RemoteEvent and thus it cant be exploited via argument spoofing / remote spy
  • Doesn’t require you to specify whether you are equipping or unequipping.

Cons

  • System may be spoofed via rapidly equipping & unequipping the tool faster than the server & client model can update / repliate. Theoretically can be prevented by either a cooldown system in the local script - OR - tracking the number of remote events fired by each player and filtering / disabling the spammers.
2 Likes

Alright, thanks for helping.

30 words needed

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.