Hi, thanks for reading.
Currently, I’m playing around with some ProximityPrompts in my place, and I was wondering how I use a PromptButtonHoldEnded function twice.
Basically what I’m doing is tweening some doors open when a user holds a ProximityPrompt for a certain amount of time, in this case it’s 0.5 seconds. Now that they are open, I’m confused how to tween them back when E is held in the same function.
Here is my code right now:
local TweenService = game:GetService("TweenService")
local TwnInfo = TweenInfo.new(2, Enum.EasingStyle.Sine)
local Wood = script.Parent.Parent.Parent.Parent.WoodWork
local Panel = script.Parent.Parent.Parent.Parent.DoorPanel
local ProximityPrompt = script.Parent
local Tween1 = TweenService:Create(Wood, TwnInfo, {Position = Vector3.new(34.125, 4.875, 38)})
local Tween2 = TweenService:Create(Panel, TwnInfo, {Position = Vector3.new(34.125, 6.125, 38)})
ProximityPrompt.PromptButtonHoldEnded:Connect(function(End)
Tween1:Play()
Tween2:Play()
ProximityPrompt.ActionText = "Close Door"
end)
So far I have looked this up and found nothing since ProximityPrompts are relatively new.
Basically all I’m saying is How do I tween the doors back in the same function, i.e if the user holds E again.
Store a boolean value in a variable that detects if the doors are opened or not, and in the .PromptButtonHoldEnded connection, have an if then else end statement for whether the door already open or not.
1 Like
Here is the updated code for anyone who needs it:
local TweenService = game:GetService("TweenService")
local TwnInfo = TweenInfo.new(2, Enum.EasingStyle.Sine)
local Wood = script.Parent.Parent.Parent.Parent.WoodWork
local Panel = script.Parent.Parent.Parent.Parent.DoorPanel
local ProximityPrompt = script.Parent
local Open = false
local Tween1 = TweenService:Create(Wood, TwnInfo, {Position = Vector3.new(34.125, 4.875, 38)})
local Tween2 = TweenService:Create(Panel, TwnInfo, {Position = Vector3.new(34.125, 6.125, 38)})
local Tween3 = TweenService:Create(Wood, TwnInfo, {Position = Vector3.new(34.125, 4.875, 31.5)})
local Tween4 = TweenService:Create(Panel, TwnInfo, {Position = Vector3.new(34.125, 6.125, 31.5)})
ProximityPrompt.PromptButtonHoldEnded:Connect(function(End)
if Open == false then
Tween1:Play()
Tween2:Play()
ProximityPrompt.ActionText = "Close Door"
Open = true
elseif Open == true then
Tween3:Play()
Tween4:Play()
ProximityPrompt.ActionText = "Open Door"
Open = false
end
end)
https://gyazo.com/c515975bec261d95d2a844a2ec3b5807
It worked, thank you @myaltaccountsthis !
1 Like