I would like to share some of my insights diving into Proximity Prompts.
I recently implemented them for my Loot objects in my game, to update the older system of adorning a subject billboard gui with the Loot object.
Using proximity prompts you can use that signal for whatever you want.
In this code example I am using it to set some values based on the proximity prompt object which has Line of Sight capabilities.
I may replace my targeting system with something like this in the future because it is super fast!
Using these you can use it for things like enemy targeting by setting a Theme and making an exception in the script located in the object name “ProximityPromptScript”.
if promptTheme=="Loot" then
frame.Item.ItemID.Value=prompt.Parent.Parent.Parent.Name
--render the item
PlayerGui.LootGui.SubjectItem.Value=frame.Item.ItemID.Value--String Value of the model
PlayerGui.LootGui.Loot.Value=prompt.Parent--object value of the adorned object
local ItemProcessor=PlayerGui.Bars.Inventory.Supplied.LocalProcessor--Dynamic Inventory Processor
ItemProcessor:Invoke("IDItem",{frame.Item,frame.Item.ItemID})--Render the item icon.
end
You can try out my version of the script I have modified and use the signal for whatever, you can disable the “prompt” by the Enable property being set to false.
This is new and exciting information for me if anyone else has any insights feel free to share!
ProximityPromptService.PromptShown:Connect(function(prompt, inputType)
if prompt.Style == Enum.ProximityPromptStyle.Default then
return
end
local gui = getScreenGui()
local cleanupFunction = createPrompt(prompt, inputType, gui)
prompt.PromptHidden:Wait()
cleanupFunction()
end)
```
So use a Custom-styled prompt with RequiresLineOfSight disabled to detect when a player enters a spherical zone? That’s pretty creative. If that’s not what the post is about then I didn’t really understand it
Yeah that’s what the post is about, using a proximity prompt with RequiresLineOfSight disabled or enabled. is’ very simple and effective way to target a object locally by the Theme attribute. To add a new Theme simply add a attribute to a proximity prompt called Theme set it to the name and make sure the style is set from “Default” to “Custom” on the proximity prompt.
I think it would be useful for a coin collector where a local player collects a reward by approaching the proximity prompt instead of triggering it…
How sure are you Roblox uses a more performant method of checking distances internally for proximity prompts? I’m pretty sure they still use distance magnitude checks. The thing is, you shouldn’t really notice any performance impact of a simple distance check unless it is in the form of hundreds every heartbeat or so. I’m not really too sure if your goal of doing this is peformance, but if so the performance shouldnt be any greater than looping through all the “points” and checking the distance yourself. Although I do agree the built in signals they have are pretty handy. Would be interesting to run a benchmark on proximity prompts when used in mass.
Also, exploiters can fire proximity prompts even when not in range. I suggest adding a sanity check on the server to make sure the player is actually withon a valid distance, especially for something like loot that can be picked up.
I have a custom renderer so that the loot only exists when it is in view. Otherwise, it is compressed to a reference of the source object and the original object destroyed to free up memory. I haven’t had the time to really go through the proximity prompt code. I’ll look at it now.
For example, say you had a door that typically takes a proximity prompt trigger to open. You could make it open when the player is in range instead of triggering it via input and skip making a prompt gui.
The basic signal appears to be this that triggers when the prompt is in range. To reduce load you would
promptTheme=prompt:GetAttribute("Theme")
ProximityPromptService.PromptShown:Connect(function(prompt, inputType)
if prompt.Style == Enum.ProximityPromptStyle.Default then
return
end
local gui = getScreenGui()
local cleanupFunction = createPrompt(prompt, inputType, gui)
prompt.PromptHidden:Wait()
cleanupFunction()
end)
I believe that is the key signal for taking advantage of proximity prompt objects. I haven’t done much to implement this feature yet but I tried figuring it out in the past to no avail so perhaps this post might provide helpful insight. Although, in hindsight it seems pretty basic.
The other signals available by a proximity prompt are as follows according to the proximitypromptscript code.
if prompt.HoldDuration > 0 then
holdBeganConnection = prompt.PromptButtonHoldBegan:Connect(function()
for _, tween in ipairs(tweensForButtonHoldBegin) do
tween:Play()
end
end)
holdEndedConnection = prompt.PromptButtonHoldEnded:Connect(function()
for _, tween in ipairs(tweensForButtonHoldEnd) do
tween:Play()
end
end)
end
triggeredConnection = prompt.Triggered:Connect(function()
for _, tween in ipairs(tweensForFadeOut) do
tween:Play()
end
end)
triggerEndedConnection = prompt.TriggerEnded:Connect(function()
for _, tween in ipairs(tweensForFadeIn) do
tween:Play()
end
end)
I plan on making some cool stuff with this feature in the future.