I’m trying to check if all proximity prompts in the workspace has a HoldDuration greater than 0. If so, then it will change the text that will pop up when the prompt is shown. The text does pop up, but it does not change at all for some reason when a prompt with a HoldDuration greater than 0 appears. Am I doing the for loop correct at all?
if userInput.TouchEnabled and not userInput.KeyboardEnabled and not userInput.MouseEnabled then
interact.Text = "Tap Prompt to Interact"
for i, prompts in pairs(workspace:GetDescendants()) do
--check if prompt needs to be held
if prompts.HoldDuration > 0 then
interact.Text = "Hold Prompt to Interact"
end
if prompts.HoldDuration == 0 then
interact.Text = "Press Prompt to Interact"
end
end
elseif not userInput.TouchEnabled and userInput.KeyboardEnabled and userInput.MouseEnabled then
interact.Text = "Press E to Interact"
--check if prompt needs to be held
if prompts.HoldDuration > 0 then
interact.Text = "Hold E to Interact"
end
if prompts.HoldDuration == 0 then
interact.Text = "Press E to Interact"
end
end
end
for i, prompts in pairs(workspace:GetDescendants()) do
--check if prompt needs to be held
if prompts.HoldDuration > 0 then
interact.Text = "Hold Prompt to Interact"
end
if prompts.HoldDuration == 0 then
interact.Text = "Press Prompt to Interact"
end
end
...
This is problematic. Very much so.
Who says every descendant of Workspace is a ProximityPrompt? The moment this script tries to access HoldDuration for an instance that doesn’t possess that property, it will stop executing.
Chances are this script is throwing an error about prompts not having the HoldDuration property. Before you do anything else, throw in an additional ifstatement that checks if prompts is actually a ProximityPrompt.
I figured that was one of the reasons, since before making this post, I got an error that HoldDuration wasn’t a property of the camera. I put the for loops in the same :IsA() that checks for mobile devices, but now it just shows the “Hold E to Interact” text regardless if the prompt has a greater HoldDuration of 0
You’re trying to change Text which isn’t a valid property of ProximityPrompt. I believe you should be changing ActionText instead.
Also, might I offer looking into ProximityPromptService? It has some useful events that detect when a ProximityPrompt appears, is triggered, is held, etc. Could be useful for on-the-fly changes, but your way is valid too.
I forgot to say that the text was actually a GUI that I have set to tween when any prompt is shown. I’m not actually changing the ActionText of the prompts. Also, the HeldDuration part is still not working
Here it is, I didn’t include it in the original post because of uhh… reasons
local player = game:GetService("Players").LocalPlayer
local userInput = game:GetService("UserInputService")
local proximitypromptService = game:GetService("ProximityPromptService")
local ui = script.Parent.Parent
local frame = ui.Frame
local interact = frame.InteractText
if userInput.TouchEnabled and not userInput.KeyboardEnabled and not userInput.MouseEnabled then
interact.Text = "Tap Prompt to Interact"
for i, prompts in pairs(workspace:GetDescendants()) do
if prompts:IsA("ProximityPrompt") then
--check for mobile
prompts:GetAttribute("Theme")
prompts:SetAttribute("Theme", "Default")
--check if prompt needs to be held
if prompts.HoldDuration > 0 then
interact.Text = "Hold Prompt to Interact"
end
if prompts.HoldDuration == 0 then
interact.Text = "Tap Prompt to Interact"
end
end
end
elseif not userInput.TouchEnabled and userInput.KeyboardEnabled and userInput.MouseEnabled then
interact.Text = "Press E to Interact"
for i, prompts in pairs(workspace:GetDescendants()) do
if prompts:IsA("ProximityPrompt") then
--check for mobile
prompts:GetAttribute("Theme")
prompts:SetAttribute("Theme", "E")
--check if prompt needs to be held
if prompts.HoldDuration > 0 then
interact.Text = "Hold E to Interact"
end
if prompts.HoldDuration == 0 then
interact.Text = "Press E to Interact"
end
end
end
end
I’d use an elseif statement instead of two chained if statements for setting the text.
I don’t see anything inherently wrong with the code itself, so I don’t know what else to say without more information. If all of the text says “Hold E To Interact” then it seems to me as if all of your prompts have a HoldDuration value greater than zero.
Maybe try using the debugger and see if you can catch any odd issues like incorrect values and the like