Why tween acting weird?

Hi, my fellow Devforumers, I was wondering a thing, that someone could kindly reply to, I have this piece of script, at a quick look, it looks correct , right?, but… the truth is, It’s acting weird!, let me break it for you

task.wait(.15)
local TweenService = game:GetService("TweenService")

local UI = script.Parent
local SettingsButton = UI:WaitForChild("Sbutton")
local SettingsBG = UI:WaitForChild("bg")
local StrokeSettingsBG = SettingsBG:WaitForChild("UIStroke")
local NightcoreButton = SettingsBG:WaitForChild("NightButton")
local NightcoreBG = UI:WaitForChild("nightcoreBg")
task.delay(1, function()
	SettingsBG.ImageTransparency = 1
	SettingsBG.Position = UDim2.new(0.284, 0,0.525, 33)
	NightcoreButton.TextTransparency = 1
	StrokeSettingsBG.Transparency = 1
end)

local tInfos = {
	AppearSettingsBG_info = TweenInfo.new(
		0.6,
		Enum.EasingStyle.Sine
	),
	DisappearSettingsBG_info = TweenInfo.new(
		0.5,
		Enum.EasingStyle.Sine
	),
}

local tweens = {
	SettingsBGAppear = TweenService:Create(
		SettingsBG,
		tInfos["AppearSettingsBG_info"],
		{ImageTransparency = 0.6 ,Position = UDim2.new(0.285, 0,0.499, 0)}
	),
	SettingsBGDisappear = TweenService:Create(
		SettingsBG,
		tInfos["AppearSettingsBG_info"],
		{ImageTransparency = 1 ,Position = UDim2.new(0.284, 0,0.525, 33)}
	),
	UIStrokeAppear = TweenService:Create(
		StrokeSettingsBG,
		tInfos["AppearSettingsBG_info"],
		{Transparency = 0}
	),
	UIStrokeDisappear = TweenService:Create(
		StrokeSettingsBG,
		tInfos["DisappearSettingsBG_info"],
		{Transparency = 1}
	),
	NightcoreButtonAppear = TweenService:Create(
		NightcoreButton,
		tInfos["AppearSettingsBG_info"],
		{TextTransparency = 0}
	),
	NightcoreButtonDisappear = TweenService:Create(
		NightcoreButton,
		tInfos["DisappearSettingsBG_info"],
		{TextTransparency = 1}
	),
}

local OnSettings = false

SettingsButton.MouseButton1Click:Connect(function()
	if not OnSettings then
		OnSettings = true
		print("open")
		
		tweens["UIStrokeDisappear"]:Cancel()
		tweens["NightcoreButtonDisappear"]:Cancel()
		tweens["SettingsBGDisappear"]:Cancel()
		
		tweens["SettingsBGAppear"]:Play()
		tweens["UIStrokeAppear"]:Play()
		tweens["NightcoreButtonAppear"]:Play()
		
		
	else
		OnSettings = false
		print("close")
		
		tweens["UIStrokeAppear"]:Cancel()
		tweens["NightcoreButtonAppear"]:Cancel()
		tweens["SettingsBGAppear"]:Cancel()
		
		tweens["SettingsBGDisappear"]:Play()
		tweens["UIStrokeDisappear"]:Play()
		tweens["NightcoreButtonDisappear"]:Play()
		
	end
end)

tweenbug2
tweenbug

When i click it slowly, it works perfect, but when i start clicking it too fast, it bugs!, or sometimes it disappears only the text and even stays static, the way i need it to work is , no matter how fast you are clicking it, it won’t bug and also play the correct tween when closing/opening

2 Likes

are you sure it isn’t because the tweens are overlapping eachother

1 Like

Yeah, but i saw other games do the same, and it wouldn’t matter, never bugged

uhhh i don’t know the problem

but i would suggest spoilering those seizure-inducing gifs

1 Like

I Managed it to work by adding

for k,n in pairs(tweens) do
		n:Cancel()
	end

on both closing and opening functions, but, someone can explain why this happens?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.