Modularizing Interaction System(E to Interact)

Place file: Interaction System_For-Code-Review.rbxl (23.2 KB)

  • What does the code do and what are you not satisfied with?
    The code Fires different BindableEvents if the Part is tagged with “Interactive” when E is pressed or held down for a set time(If the part has a HoldTime IntValue that is greater than 0) based on which Part you are close to and looking at

  • What potential improvements have you considered?
    I want to make the system modular.

  • How (specifically) do you want to improve the code?
    I want to make the code cleaner, currently, I feel like the code is kinda all over the place

1 Like

Suggested improvements:
InteractionGui in ReplicatedStorage? Extra setup steps for user. Store inside InteractionSystemClient instead, for ease of use and to make it more self- contained. Also, BindableInteractions and InteractionsConnections need to be set up by the developer. Move InteractionSystemClient to StarterPlayerScripts, and make the necessary folders children of InteractionSystemClient. That way, all relevant configuration is contained in that one LocalScript.

Lines 55-69 InteractionSystemClient:
Deeply nested if statements. Split into separate function at line 60. E.g.
if keyPressed == Enum.KeyCode.E then
interact()
end

Have a reference to the interactible that is currently closest, instead of referring to it as InteractionGui.Adornee. It’s not very readable the way it currently is.

Replace os.time() with tick(), because os.time() returns whole seconds, while tick() is much finer. Developer should be able to set e.g. 2.2 seconds hold time.

Additional features:
InteractionSystemClient:
Why force developer to use the ‘E’ key? Make key configurable, add support for touch and gamepad, make it possible to change the “interact” key during gameplay, e.g. to disable interacting completely or allow player to rebind controls. Make GUI update accordingly.

GUI:
Player feedback for interactions w/ hold time. Bar that fills up, circle that grows to match ring, anything to make it less mysterious what is going on. If a player moves away from an interactible w/ hold time while holding ‘E’, it’s also a bit confusing that it just stops w/ no feedback. Also the GUI needs more work in general.

Hope this helps :slight_smile:

4 Likes

I’m guessing I should utilize ContextActionService for this?

I did that after I posted in code review

I made the changes you suggested