So I’ve been trying to solve this issue for a long time, the function below is connected to a Touched Event, and it will fire every time a player touches a part.
My problem is that this function gets fired way too many times when a player touches a part. I know the reasonable way would be to add a debounce for the touched event but that does not help for my specific case.
What I’m trying to achieve is, I want to be able to know inside the function,
if the tweens are currently playing, if they are playing, do nothing, if they are not playing, proceed with the function and play the partTween and ReverseTween.
I tried looking into TweenBase.PlayBackState but I have no idea how to format it with this.
Any help would be appreciated!
local function createTween(part, platestringvalue, trapstringvalue)
local primary = trapstringvalue.Parent.primary
local info = TweenInfo.new(
--time, easingstyle repeatcount(negative number loops indefinitely), reverses(true/false), delay
0.3,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false
)
local primaryposition = primary.CFrame
local position = {
CFrame = primary.CFrame + Vector3.new(0,6,0)
}
local position2 = {
CFrame = primaryposition
}
local partTween = TweenService:Create(primary, info, position)
local function ReverseTween(Tween, ReverseProperty, DelayTime)
Tween.Completed:Connect(function()
local tweenproperty = ReverseProperty
wait(DelayTime) ---or add this to the actual tween info
local ReversedTween = TweenService:Create(primary, info, tweenproperty)
ReversedTween:Play()
return
end)
end
partTween:Play()
ReverseTween(partTween, position2, 1)
end