hey! so I’m currently wondering how I can get a triggered proximityprompt’s parent. but the problem is, is that there are multiple proximity prompts with the same name and I need to detect which one was triggered. .any help would be greatly appreciated, thank you!!!
1 Like
local ProximityPromptService = game:GetService("ProximityPromptService");
local vowelCorrect = function(Word)
local vowelTable = {
"a";
"e";
"i";
"o";
"u";
};
if vowelTable.find(Word:lower():sub(1, 1)) then return "an " .. Word end;
return "a " .. Word;
end;
ProximityPromptService.PromptTriggered:Connect(function(Prompt, Player)
local message = ("Proximity | ProximityPrompt was activated by %s and is parented to %s, which is %s!"):format(Player.Name, Prompt.Parent.Name, vowelCorrect(Prompt.Parent.ClassName));
warn(message);
end);
have you considered using tags?
do you mind explaining how that works? I’m not too experienced with that.
1 Like
It’s a plugin called tags, you just use the collection service, then for each prompts parent add a tag to it with a special name. Then all you have to do is
ProximityPrompt.Parent:FindFirstChild(“TagNameHere”) to find it.
I’m having trouble understanding and using this? do you mind explaining?
Use ProximityPromptService as you don’t need to loop through all the workspaces descendants, very very inefficient doing that.
local ProximityPromptService = game:GetService("ProximityPromptService")
ProximityPromptService.PromptTriggered:Connect(function(prompt, player)
warn(string.format("%s has activated a prompt whose parent is %s", player.Name, prompt.Parent.Name))
end)
local Workspace = workspace --Local environment integration.
local function OnPromptTriggered(Player, Prompt)
print(Player.Name.." triggered a prompt inside "..Prompt.Parent.Name..".")
end
local function GetPromptsRecursive(Instance)
for _, Child in ipairs(Instance:GetChildren()) do
if Child:IsA("PVInstance") then --Models and parts.
GetPromptsRecursive(Child) --Look inside for prompts.
elseif Child:IsA("ProximityPrompt") then
Child.Triggered:Connect(function(Player)
OnPromptTriggered(Player, Child)
end)
end
end
end
GetPromptsRecursive(Workspace) --Iterate over the Workspace initially.