I wish to make it so that a proximityprompt is only shown once a tool by the name of “Tray” is equipped. However, so far it isn’t doing what it’s supposed to, as despite the “tray” tool being held, the prompt doesn’t appear. Below you’ll find the problematic code, and the hierarchy of where the proximityprompt is shown.
Localscript
local ProximityPrompt = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function ToolEquipped(prompt)
local tool = player.Character:FindFirstChildWhichIsA("Tool")
if tool ~= nil then
prompt.Enabled = true
end
end
local function CheckPrompt(prompt)
if prompt.Name == "Tray" then
if player.Character:FindFirstChildWhichIsA("Tool") ~= nil then
prompt.Enabled = true
else
prompt.Enabled = false
player.Character.ChildAdded:Connect(function()
ToolEquipped(prompt)
end)
end
end
end
ProximityPrompt.PromptShown:Connect(CheckPrompt)
If you select the script, in the Properties tab select the RunContext dropdown and select Client.
Or, if you want the method that takes more work (not necessary but I’ll put it here for future reference if anyone needs it):
Select the script and run this in the command bar:
Just to make sure it’s not a problem with your code, move this to a LocalScript and put it in one of the locations I said (likely StarterPlayerScripts or StarterCharacterScripts in this case).
I’ve never used the RunContext feature, it’s likely I got it wrong
It seems that ProximityPrompt are no longer functional inside of the ‘model’ alone, try moving it to a BasePart in the model or inside of an attachment in `workspace.Terrain``
As 12345koip mentioned, if you want localscripts to run in workspace you have to change the RunContext Property in the properties tab of a ‘server-script’ to ‘Client’.
edit 2: make sure LineOfSight property of the ProximityPrompt is disabled.
Will only trigger if a prompt is shown, so using it to enable/disable it self isn’t the right way to do it.
What you have to do is to enable and disable the prompt based on whether the tool is in the character or not.
I linked a rbxl file to the topic above, which shows another approach to achieve the same result. You will have to change line 5 to make it work, i forgot to change it back when I uploaded the file.
That was a bad example to clean up connections, you can either look up how to clean up connections or remove that line from the script. I don’t think it will hurt as long as you’re willing to learn about them later on. Just have fun for now.
edit: i just realized that you marked the post as a solution, thank you.