Issue with tweens

I’m experimenting with the new proximity prompt feature and everything works good except I’m having an issue with the tweens. When I double click the door bugs out and changes the value which I can’t figure out whats causing it. I’ll include a video of how it should work versus what happens when you click it twice. Also a note this only happens when clicking multiple times.

I’ve tried moving the value around however I’ve been unsuccessful it seems to happen no matter where the value is. I also previously had it built in the script via this method:

local closed = true

I’ve tried everything that I can think to try which isn’t much because I’m not a super advanced scripter but I need some ideas to try.

Normal:
https://gyazo.com/3d55035a30f95dc30148bed378258f11

Double Clicking:
https://gyazo.com/e7f1e0293679dccf92c437165b2c8482

Script Used:

local TweenService = game:GetService("TweenService")
local model = script.Parent.Main
local PanelRoot = script.Parent.Main
local PanelSlideInfo = TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0) -- Opening length, easing style, easing direction, duration in seconds, overide other tweens, delay

function door()
	if script.Parent.closed.Value == true then
		local PanelSlideTween = TweenService:Create(PanelRoot, PanelSlideInfo, {
			CFrame = PanelRoot.CFrame * CFrame.new(0, 4, 0)
		})
		PanelSlideTween:Play()
		PanelSlideTween.Completed:wait()
	    script.Parent.closed.Value = false
	else
	if script.Parent.closed.Value == false then
	local PanelSlideTween = TweenService:Create(PanelRoot, PanelSlideInfo, {
		CFrame = PanelRoot.CFrame * CFrame.new(0, -4, 0)
	})
	PanelSlideTween:Play()
	PanelSlideTween.Completed:wait()
	script.Parent.closed.Value = true
end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	if player:GetRankInGroup(0) >= 1 then
		return
        script.Parent.Main.ProximityPrompt.Triggered:Connect(door)
	   else
	end
		end)
2 Likes

I would make a variable that tells whether or not it will receive input.

local Available = true
    function door()
        if Available then
            Available = false
        if script.Parent.closed.Value == true then
            ...
        Available = true
1 Like

I would make invisible part that will be tween’s finish location

1 Like

When you start a new tween the previous one is “completed” and starts a new one from the current position. Which is why it’ll finish further away, and why it’ll mark it as open early.

The .Completed:wait() will trigger once you start a new tween on the same property.

Just throw in a debounce similar to what @DoNotEatSoggyWafflez explained and you should be fine.

local debounce = false

function door()
    if debounce == false then
        -- Open/Close
    debounce = true
    end
end

This makes it so it won’t accept any inputs until the previous input has finished.

1 Like

I tried both ideas with the debounce but they don’t work the door still messes up when clicked multiple times. Also the way I have it scripted with the closed value should already work the same way as a debounce. It could be a bug with studio or the new proximity prompt as well.

1 Like

The problem is because script.Parent.closed.Value is not set to false until after the tweening is finished, so it still allows you to run through the code again.

1 Like

I see that but the reason I think its a bug is because even with the debounce it still allows for double clicking. This is what I did for the debounce. I don’t see anything wrong with what I did but I could have something wrong.

Script with debounce:

local TweenService = game:GetService("TweenService")
local model = script.Parent.Main
local PanelRoot = script.Parent.Main
local debounce = false
local PanelSlideInfo = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0) -- Opening length, easing style, easing direction, duration in seconds, overide other tweens, delay

function door()
	if not debounce then 
		if script.Parent.closed.Value == true then
		debounce = true
		local PanelSlideTween = TweenService:Create(PanelRoot, PanelSlideInfo, {
			CFrame = PanelRoot.CFrame * CFrame.new(0, 4, 0)
		})
		PanelSlideTween:Play()
		script.Parent.closed.Value = false
		debounce = false
		else
			if not debounce then 
				if script.Parent.closed.Value == false then
			debounce = true
	local PanelSlideTween = TweenService:Create(PanelRoot, PanelSlideInfo, {
		CFrame = PanelRoot.CFrame * CFrame.new(0, -4, 0)
	})
	PanelSlideTween:Play()
			script.Parent.closed.Value = true
			debounce = false
end
	end
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	if player:GetRankInGroup(0) >= 1 then
		return
        script.Parent.Main.ProximityPrompt.Triggered:Connect(door)
	   else
	end
		end)