So im making an item system for my game, and I wanted to use proximity prompts for whenever the player picks up an item, or places it onto an “itemHolder”. The player can only hold one item at a time, so i thought it would make sense to hide any proximityprompts that would be for picking up items, if you are already holding something. Also, i dont want the proximity prompts for placing items on ItemHolders to show up unless you’re holding an item. so far, this is the code ive got:
local ProximityPromptService = game:GetService("ProximityPromptService")
local Player = game.Players.LocalPlayer
ProximityPromptService.PromptShown:Connect(function(Prompt)
local Character = Player.Character
local EquippedItem = Character.EquippedItem
if Prompt.Name == "ItemPrompt" then
if EquippedItem.Value ~= nil then
-- Hide this prompt
end
end
if Prompt.Name == "ItemHolderPrompt" then
if EquippedItem.Value == nil then
-- Hide this prompt
end
end
end)
I dont know how to access the prompt’s UI to disable it, so thats really my only issue.
if Prompt.Name == "ItemPrompt" then
if EquippedItem.Value ~= nil then
Prompt.Enabled = false
end
end
if Prompt.Name == "ItemHolderPrompt" then
if EquippedItem.Value == nil then
Prompt.Enabled = false
end
end
Or just do it one at a time in each proximity prompt, though its very unpractical.
this disables the prompt itself which makes it so it won’t show up even when im not holding an item. I want to disable the ui itself, which i know is possible as long as i can access the UI that it creates when you get close
No, i mean that i just want to disable the GUI, and not make it work. So like, if im holding an item it wont show the UI but if im not holding an item it will. If i disable the prompt it wont show up either way
The proximity prompts UI is Players.Player.PlayerGui.ProximityPrompts.Prompt
The “ProximityPrompts” is a screengui that gets added whenever the first prompt is shown and doesnt get deleted afterwards.
The prompt itself is a billboardGui
The issue is if you wanna disable the gui this way I’m pretty sure clicking “E” would still make it work, even if its not visible.
is there someway to disable the UI and stop the Input from registering? But without setting Enabled to false? Because if i do it that way it would not turn back on once im not holding something
I mean you could disable it and add an additional check that checks whether or not you don’t have an item, and if you dont it re-enables it
Something like this could work:
local ProximityPromptService = game:GetService("ProximityPromptService")
local Player = game.Players.LocalPlayer
ProximityPromptService.PromptShown:Connect(function(Prompt)
local Character = Player.Character
local EquippedItem = Character.EquippedItem
if Prompt.Name == "ItemPrompt" then
if EquippedItem.Value ~= nil then
Prompt.Enabled = false
else
Prompt.Enabled = true
end
end
if Prompt.Name == "ItemHolderPrompt" then
if EquippedItem.Value == nil then
Prompt.Enabled = false
else
Prompt.Enabled = true
end
end
end)
An issue I noticed with this is that it shows the prompt for like a millisecond before hiding it, which is because it’s literally waiting for the prompt to show up before disabling it.
So, another way you could go on about doing this is having all the objects that have a prompt be inside a single folder/share a tag and then whenever the equipped items value changes you loop through the entire folder/items with the tag and disable them (this way they all disable at once with the loop)
not sure how optimized this is but this seems to be working:
local ProximityPromptService = game:GetService("ProximityPromptService")
local Player = game.Players.LocalPlayer
ProximityPromptService.PromptShown:Connect(function(Prompt)
local Character = Player.Character
local EquippedItem = Character.EquippedItem
if Prompt.Name == "ItemPrompt" then
if EquippedItem.Value ~= nil then
Prompt.Enabled = false
EquippedItem.Changed:Connect(function(Value)
if Value == nil then
Prompt.Enabled = true
end
end)
end
end
if Prompt.Name == "ItemHolderPrompt" then
if EquippedItem.Value == nil then
Prompt.Enabled = false
EquippedItem.Changed:Connect(function(Value)
if Value ~= nil then
Prompt.Enabled = true
end
end)
end
end
end)
Im decently sure you’d have to disable the connection after it fires sicne this could lead to the connections stacking (test it out with print statetments; if it prints multiple times the connection has stacked)
And don’t worry about optimization for now as it’s more important to get the functionality working first
Ive made it this and it seems to work perfectly without any stacked connections
local ProximityPromptService = game:GetService("ProximityPromptService")
local Player = game.Players.LocalPlayer
local Connections = {}
ProximityPromptService.PromptShown:Connect(function(Prompt)
local Character = Player.Character
local EquippedItem = Character.EquippedItem
if Prompt.Name == "ItemPrompt" then
Item(Prompt, EquippedItem.Value)
if not Connections[Prompt] then
Connections[Prompt] = EquippedItem.Changed:Connect(function(Value)
Item(Prompt, Value)
print("stack")
end)
end
end
if Prompt.Name == "ItemHolderPrompt" then
ItemHolder(Prompt, EquippedItem.Value)
if not Connections[Prompt] then
Connections[Prompt] = EquippedItem.Changed:Connect(function(Value)
ItemHolder(Prompt, Value)
print("stack")
end)
end
end
end)
function Item(Prompt, Value)
Prompt.Enabled = (Value == nil)
end
function ItemHolder(Prompt, Value)
Prompt.Enabled = not (Value == nil)
end