Ask Your Question
0

How can the ProximityPrompt be displayed only when an item is being held?

asked 2023-06-28 12:28:29 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-28 12:47:02 +0000

plato gravatar image

One way to display the ProximityPrompt only when an item is being held is to use a script that checks if the player is holding the item and toggles the visibility of the ProximityPrompt accordingly.

First, create a ProximityPrompt and attach it to the item that you want to display it for. Set the PromptDistance property to the distance you want the prompt to appear and set the ActionText to the desired text.

Next, add a script to the item that will check if it is being held by the player. Inside the script, you can use the IsHeld property of the Tool object to determine if the item is being held by the player.

If the item is being held, set the ProximityPrompt Enabled property to true to display the prompt. Otherwise, set it to false to hide the prompt. Here's an example script:

local tool = script.Parent -- the item that the ProximityPrompt is attached to
local prompt = tool.ProximityPrompt -- the ProximityPrompt component

function onEquipped()
    prompt.Enabled = true -- show prompt when item is equipped
end

function onUnequipped()
    prompt.Enabled = false -- hide prompt when item is unequipped
end

tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)

In this script, the onEquipped and onUnequipped functions are connected to the Equipped and Unequipped events of the item, which are fired when the player equips or unequips the item. When the item is equipped, the ProximityPrompt is enabled to show the prompt. When it is unequipped, the ProximityPrompt is disabled to hide the prompt.

With this script, the ProximityPrompt will only be displayed when the item is being held by the player.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-28 12:28:29 +0000

Seen: 11 times

Last updated: Jun 28 '23