Hello fellow Roblox Developers,
I’m currently working on a project that involves implementing interactive elements using ProximityPrompts. I’ve created two scripts, one for managing interactions and the other for handling those interactions, but I’m encountering some issues and could use some assistance from the community.
Intentions:
1. “Interactions” Module Script: This script defines various types of interactions, such as using ATMs, giving items, and changing teams. It handles ProximityPrompt configurations, action texts, and object texts. The goal is to enable players to interact with objects in the game based on their permissions, team, and other attributes.
Module Script
local lawEnforcementTeams = {
["Police"] = true,
["SWAT"] = true,
}
local InteractionModule = {}
local interactionsConfig = {
{
Type = "ATM",
ObjectText = "ATM",
ActionText = "USE ATM",
Callback = function(player)
end
},
{
Type = "Give",
ActionText = "TAKE ITEM",
Callback = function(player, itemName)
local item = game.Lighting.Items:FindFirstChild(itemName)
if item then
local backpack = player.Backpack
if backpack then
local clone = item:Clone()
clone.Parent = backpack
end
end
end
},
{
Type = "Team",
ActionText = "CHANGE TEAM",
Callback = function(player, teamName)
local currentTeamName = player.Team.Name
if currentTeamName == teamName then
player.Team = game.Teams["Civilian"]
elseif game.Teams:FindFirstChild(teamName) then
player.Team = game.Teams[teamName]
end
end
},
}
function InteractionModule.SetPromptActionText(prompt, actionText)
prompt.ActionText = actionText
end
function InteractionModule.SetPromptObjectText(prompt, objectText)
prompt.ObjectText = objectText
end
function InteractionModule.HandleInteraction(interactionPart)
local proximityPrompt = interactionPart:FindFirstChildOfClass("ProximityPrompt")
if proximityPrompt then
local typeAttribute = proximityPrompt:GetAttribute("Type")
local idAttribute = proximityPrompt:GetAttribute("Id")
local rAttribute = proximityPrompt:GetAttribute("R")
local itemAttribute = proximityPrompt:GetAttribute("Item")
local leAttribute = proximityPrompt:GetAttribute("LE")
local teamAttribute = proximityPrompt:GetAttribute("Team")
print("Handling interaction for type:", typeAttribute)
for _, config in ipairs(interactionsConfig) do
if typeAttribute == config.Type then
print("Found matching config for type:", config.Type)
InteractionModule.SetPromptActionText(proximityPrompt, config.ActionText)
if config.Type == "Team" then
InteractionModule.SetPromptObjectText(proximityPrompt, teamAttribute)
elseif config.Type == "Give" and itemAttribute then
InteractionModule.SetPromptObjectText(proximityPrompt, itemAttribute)
else
InteractionModule.SetPromptObjectText(proximityPrompt, config.ObjectText)
end
proximityPrompt.Triggered:Connect(function(player)
print(player.Name .. " triggered interaction with type:", typeAttribute)
local hasPermission = true
if idAttribute and idAttribute ~= 0 then
hasPermission = player:GetRankInGroup(idAttribute) > 0
end
if hasPermission then
if rAttribute and player:GetRankInGroup(idAttribute) < rAttribute then
print(player.Name .. " does not have sufficient rank for this interaction.")
return
end
if leAttribute and not lawEnforcementTeams[player.Team.Name] then
print(player.Name .. " does not have permission for this law enforcement interaction.")
return
end
if config.Type == "Give" and itemAttribute then
print(player.Name .. " is receiving item:", itemAttribute)
config.Callback(player, itemAttribute)
elseif config.Type == "Team" and teamAttribute then
print(player.Name .. " is changing team to:", teamAttribute)
config.Callback(player, teamAttribute)
else
config.Callback(player)
end
else
print(player.Name .. " does not have permission for this interaction.")
end
end)
break
end
end
end
end
return InteractionModule
2. “InteractionHandler” Local Script: This script is responsible for initializing and managing interactions using the “Interactions” module. It identifies interaction parts in the workspace and connects them to the appropriate interaction functions. However, there seems to be an issue, as the interactions are not working as expected.
Local Script
local moduleName = "Interactions"
local interactionsModule = game:GetService("ReplicatedStorage"):WaitForChild("Shared"):FindFirstChild(moduleName)
if interactionsModule then
local InteractionsModule = require(interactionsModule)
local function initializeInteractions()
local interactionsFolder = game.Workspace:WaitForChild("Interactions")
for _, interactionPart in ipairs(interactionsFolder:GetChildren()) do
if interactionPart:IsA("Part") then
print("Initializing interaction for part:", interactionPart.Name)
InteractionsModule.HandleInteraction(interactionPart)
end
end
end
initializeInteractions()
else
warn("Interactions module not found:", moduleName)
end
Issues Faced
A few days ago, everything was working as intended. However, now I’m encountering unexpected behavior where interactions have stopped functioning. The scripts were operational initially, and I haven’t made any changes to them. Currently, I’m experiencing the following problems:
1. No Output or Errors: When testing the interactions, I noticed that no debug prints are being displayed in the Output panel. There are no error messages or warnings that could indicate what might be going wrong.
2. Interaction Functions Not Executing: The interaction functions specified in the “Interactions” module script are not being executed. For example, the code inside the Callback
functions, such as team changes or item giving, is not being triggered when players interact with the objects.
I’ve thoroughly reviewed the scripts, but I’m unable to identify the cause of these issues. It’s perplexing because the scripts were functional before, and I haven’t made any recent changes that could have caused this behavior. I’m at a loss as to why these problems have surfaced suddenly.
If anyone has encountered similar problems or has insights into what might be causing these changes in behavior, I would greatly appreciate your guidance.