Quick question about managing multiple proximity prompts in your game

Hello, I am a little stuck on this and not sure if this is a normal way to manage multiple prompts in your game or if this is a proper way

I’m wanting to check what proximity prompt the player is triggering and right now when they trigger a prompt, I check for the prompts name, and then run certain code depending on the name of the prompt

I made some examples to make it clear

I just need to know if this is a good way of what I’m trying to do cause its doesnt sound like proper way lol

function Module.PromptTriggered(Prompt)

	Prompt.Triggered:Connect(function()

		if CoolDown then return end
		CoolDown = true
		
		
		if Prompt.Name == "Test1" then
			
			-- Example: when triggered the player strinks
			
		elseif Prompt.Name == "Test2" then
			
			-- Example: when triggered the player gets teleported
			
		elseif Prompt.Name == "Test3" then
			
			-- Example: when triggered the player gets 100 cash
			
		end
		

		task.wait(1)
		CoolDown = false

	end)

end
2 Likes

You could connect an individual function to each proximity prompt. Api reference: ProximityPrompt.Triggered

1 Like

hmm, I am not sure what you mean by that and the code on that page is long, do you mean like referencing all prompts in a variable and connect them to seperate function?

1 Like

No, I mean connect a separate function to each individual proximity prompt. Example:

local p1 = workspace.Part.ProximityPrompt
local p2 = workspace.OtherPart.ProximityPrompt

p1.Triggered:Connect(function(player)
--do whatever
end)

p2.Triggered:Connect(function(player)
--do whatever
end)

2 Likes

I agree with what Lit is saying, is there a reason why you want to run all the proximity prompts events through a single function? otherwise I don’t see why you wouldn’t just make separate functions.

Its really a question of would you rather have one long script with multiple if else statements, or you could have one long script / multiple scripts with functions for each trigger event

Edit: Personally i would just make one script for each proximity prompt, and parent the script to the prompt itself, Its much more orderly in my head

1 Like

yeah thats not gonna work and its gonna be hard to keep up with where the prompts are

I’m just gonna do what I’m doing already but I’m gonna script the proximity prompts in separate modules and parent the modules under the proximity prompt module but thanks for the help from both of you