#tween playing before finished

23 messages · Page 1 of 1 (latest)

frank steeple
#
script.Parent.primary.Touched:Connect(function(hit)
    
    if hit.Parent:FindFirstChild("Humanoid") then
        
script.Parent.PrimaryPart = script.Parent.primary

local primary = script.Parent.PrimaryPart
local model = script.Parent
local targetPosition = primary.CFrame + Vector3.new(0,10,0)
local ts = game:GetService("TweenService")

local ti = TweenInfo.new(7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true)

local goal = {}
goal.CFrame = targetPosition

local tween = ts:Create(primary, ti, goal)

        tween:Play()
        
--sound
local sound = script.Parent["Large Door Open [2]"]
sound.Pitch = 0.7
if sound.IsPlaying then
    return
else
    sound:Play()
end
end


end)

hi, the script I'm making is for a door open animation, once the player touches the door the animation starts playing. but if the player touches the door while the tween is playing, the door gets bugged and it doesn't close fully. I've tried patching it by integrating

if tween.PlaybackState == Enum.PlaybBackState.Playing then
wait()
end

into it but that didn't work. if anyone knows a fix, it would be greatly appreciated.

(Basically I need the script to wait until the tween is finished, then another tween can be played)

velvet agate
cursive mantle
#

When a player touches the part and moves, it connects the function multiple times, that's probably what's happening

velvet agate
cursive mantle
#

Did you use debounce or anything?

velvet agate
#

Yes oh wait yea he dibt do that

frank steeple
#

the whole script is above, didn't use debounce

velvet agate
frank steeple
#

i will try

cursive mantle
# frank steeple i will try

make it like this:

local debounce = false

if debounce then return end
debounce = true

-- Logic here

debounce = false
#

you can add a task.wait() to work like a cooldown before setting it to false again

frank steeple
#

idk if I did it wrong or something but the debounce thing doesn't work

pale anvilBOT
#

studio** You are now Level 2! **studio

frank steeple
#
local debounce = false

if debounce then return end
debounce = true

script.Parent.primary.Touched:Connect(function(hit)
    
    
    if hit.Parent:FindFirstChild("Humanoid") then
        
script.Parent.PrimaryPart = script.Parent.primary

local primary = script.Parent.PrimaryPart
local model = script.Parent
local targetPosition = primary.CFrame + Vector3.new(0,10,0)
local ts = game:GetService("TweenService")

local ti = TweenInfo.new(7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true)

local goal = {}
goal.CFrame = targetPosition

local tween = ts:Create(primary, ti, goal)

        tween:Play()
        
--sound
local sound = script.Parent["Large Door Open [2]"]
sound.Pitch = 0.7
if sound.IsPlaying then
    return
else
    sound:Play()
end
end

end)

task.wait(7)

debounce = false



didn't work

cursive mantle
#

you have to put it inside the function

frank steeple
#

you mean inside this function?

#

tried it, didn't work and the sound is gone

calm breach
# frank steeple ```lua script.Parent.primary.Touched:Connect(function(hit) if hit.Paren...
local door = script.Parent
local primary = door.primary
local sound = door["Large Door Open [2]"]
local ts = game:GetService("TweenService")

local isAnimating = false

local function animDoor()
    if isAnimating then return end
    isAnimating = true

    door.PrimaryPart = primary
    local targetPosition = primary.CFrame + Vector3.new(0, 10, 0)

    local ti = TweenInfo.new(7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true)
    local goal = {CFrame = targetPosition}

    local tween = ts:Create(primary, ti, goal)

    sound.Pitch = 0.7
    if not sound.IsPlaying then
        sound:Play()
    end

    tween:Play()
    tween.Completed:Wait()

    isAnimating = false
end

primary.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        animDoor()
    end
end)```
#

isAnimating is the debounce variable

frank steeple
#

script works, thanks for the help

#

tried it