Custom Interaction System

Resource links:

Uncopylocked game:
Interaction System - Roblox
Roblox .rbxl file:
Interaction System.rbxl (89.0 KB)

System Explanation:

This is a custom Interaction system inspired by the one in ARC-478. Objects can be interacted with by hovering the mouse over them. Inside of the Config modulescript, you can adjust a few variables, which will be explained later.

Setting up:

To make an object interactable, you will need to copy the Config Modulescript & the Interaction boolean value from one of the three preset objects. These two elements can be added inside of a model or a part. The next thing is to edit the config modulescript.
The Interaction_ID variable is used to identify the object by scripts.
The ObjectText is used by the Interaction UI
The Key is the KeyCode used by the script to detect an interaction & the Holdduration is how long the player has to hold the key for
Once you have done this, the object will be interactable in the game.
You can also edit the distance in which objects will be registered in the Interaction client script

Scripting an Object:

First, identify if the behavior you want at the end of the Interaction is going to be on the client or the server. If it should be run on the client, then go to the Interaction localscript found in StarterPlayerScripts and scroll down to the OnInteractedEvent Event. If it should be run on the server, then go to the Interaction_Server script in ServerScriptService, find the RemoteEvent’s OnServerEvent event. (Of course you can make the behavior run on the server & client)
Now, to identify the object, add a new elseif statement (or an if one if you decide to remove the preset one), like so:
if Config.Interaction_ID == “” then
– do stuff
elseif Config.Interaction_ID == “a” then
– do more stuff
end

I’m always open for feedback / questions regarding my systems. If you are going to use this system in your game then a credit would be appreciated, but not necessary.

26 Likes

:astonished: :exploding_head:

This is really nice looking!

It would be perfect in a Story Game or Adventure Map!

Great work!

3 Likes

This is a very nice system, but for readability and performance I would suggest steering away from a long chain of elseif statements. You should rather opt for modularized independent functions customized for each Interaction_ID on the client and server.

Below is a revised version with the changes implemented! The foundation of the system is intact but the methods in which the client and server handle the reactions to the events being fired has been changed to be more efficient. You’ll find a folder named IneractionObjects inside both the client/server interaction scripts which holds the ID specific modules that will be executed when the interaction events are fired.

Revised File: Revised Interaction System.rbxl (91.3 KB)


This significantly cuts down on the space needed for the same functionality which works the same way on the Client & Server.

Lua Code Snippet (Dropdown)
Interaction_RE.OnServerEvent:Connect(function(player: Player, context: string, part: BasePart)
	if context ~= "PromptInteracted" then return end
	if part == nil then return end
	
	local Config = require(part:FindFirstChild("Config"))
	local InteractionId = Config.Interaction_ID
	
	-- Gets the available module which will run on the corresponding Config.Interaction_ID
	local InteractionObjectFunction = InteractionObjects:FindFirstChild(InteractionId)
	
	if InteractionObjectFunction then
		-- Execute with a safeguard precaution pcall()
		local success, errors = pcall(function()
			require(InteractionObjectFunction)(player, context, part)
		end)
		
		if not success then
			error(errors)
		end
	end
end)

Thank you for your contribution to the Roblox Open Source community, can’t wait to see what you publish next!

7 Likes

Thank you for the contribution! I was going for the usual way to handle interactions with proximity prompts (at least the way I’ve been doing it), where you check a property of the proximity prompt, such as the name (in this case the Interaction_ID) with an if statement.

1 Like