What do you want to achieve? a variable that increments for every second that you hold down a ProximityPrompt
What is the issue? I don’t know how to do this in a clean effective way.
What solutions have you tried so far? I do have one way to do this but the way that I currently have is very messy and I don’t like it, here is the way I’m currently doing stuff:
local isDone
ProximityPrompt.PromptButtonHoldBegan:Connect(function()
isDone = false
repeat
value += 1
wait(1)
until isDone
end)
ProximityPrompt.PromptButtonHoldEnded:Connect(function()
isDone = true
end)
is there a more clean way to do this, or is it possible to do something like repeat code until ProximityPrompt.PromptButtonHoldEnded:Wait()
tldr; I want to increment a value for every second that a player holds down a ProximityPrompt
local pressed
local heldFor
ProximityPrompt.PromptButtonHoldBegan:Connect(function()
heldFor = os.time()
pressed = true
while pressed do
if not ProximityPrompt.PromptButtonHoldEnded:Wait() then
heldFor = (os.time() - heldFor)
else
pressed = false
return
end
end
end)
Your code to me seems fine, though. But this way that I’m doing is just using os.time() to change the value, and listening for when the player stops holding the prompt.
what I mean is I don’t like how chunky the code was. I want something that’s small and doesn’t need variables to check if your pressing the prompt. though I might be asking for too much.
ProximityPrompt.PromptButtonHoldBegan:Connect(function()
local Status = false
ProximityPrompt.PromptButtonHoldEnded:Once(function()
Status = true
end)
repeat
Value += 1
task.wait(1)
until Status
end)
is the smallest u can reasonably make this unfortunately
local Script = script
local Prompt = Script.Parent
local Value = 0
local function OnPromptButtonHoldBegan(BeganPlayer)
local Connection
local function OnPromptButtonHoldEnded(EndedPlayer)
if BeganPlayer == EndedPlayer then Connection:Disconnect() end
end
Connection = Prompt.PromptButtonHoldEnded:Connect(OnPromptButtonHoldEnded)
while Connection.Connected do
task.wait(1)
Value += 1
end
end
Prompt.PromptButtonHoldBegan:Connect(OnPromptButtonHoldBegan)