Help making a timer so an image disappears after 3 seconds, but if it changes transparency before reset the timer

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? After the player changes the transparency of the image i want it so after 3 seconds its transparency is set to 1, but if it changed before its set to 1 then reset the timer ( sorry if i didn’t explain well )

  2. What is the issue? The issue is, it’s making the transparency set to 1 immediately, and if i set a task.wait(time) it doesnt reset the timer.

  3. What solutions have you tried so far? I tried searching things about tick() but yeah, im not good with it and i didn’t find any solution for my problem.

local function check()
	local maxTime = 3

	currTime = tick()
	local passedTime = currTime - prevTime
	for i=1,3 do
		if passedTime >= maxTime then
            task.wait(maxTime)
			hideTween:Play()
			return
		end
	end
end

visibilityInt.Changed:Connect(function()
	if visibilityInt.Value == 1 then
		
		visibleTween:Play()
		visibleTween2:Play()
		
	elseif visibilityInt.Value == 2 then
		
		crouchingVisibleTween:Play()
		crouchingVisibleTween2:Play()
		
	elseif visibilityInt.Value == 3 then
		
		hidingVisibleTween:Play()
		hidingVisibleTween2:Play()
		
	elseif visibilityInt.Value == 4 then
		
		asSeenSound:Play()
		
		asSeenFrameTransparency1:Play()
		
		asSeenTweenSize1:Play()
		asSeenTweenColor:Play()
		
		local rotateTimes = 30
		repeat
			rotateTimes = rotateTimes - 0.3
			eyeVisibility.Rotation = math.random(-rotateTimes,rotateTimes)
			task.wait()
		until rotateTimes <= 0
		
		asSeenFrameTransparency2:Play()
		asSeenTweenSize2:Play()
	end
check()
end)

See the video, when i change it too fast the image gets invisible a lot faster than 3 seconds.

Help please

1 Like

try this

local timer = tick()
local LifeTime = 5

image:GetPropertyChangedSignal("Transparency"):Connect(function()
timer = tick()
end)

repeat wait() until tick()-timer >= LifeTime

image:Destroy()
1 Like
local function check()
	local timer = tick()
	local LifeTime = 5

	eyeVisibility:GetPropertyChangedSignal("Transparency"):Connect(function()
		timer = tick()
	end)

	repeat wait() until tick()-timer >= LifeTime

	eyeVisibility:Destroy()
end

so like this? i didn’t understand how that would work

So i tried that, and changed the eyeVisibility:Destroy() to hideTween:Play()

And it works, but theres still 1 problem, if you change the value too fast when changing it again later it doesnt wait the LifeTime value to play the tween.

local function check()
	local timer = tick()
	local LifeTime = 5

	eyeVisibility:GetPropertyChangedSignal("Transparency"):Connect(function()
		timer = tick()
	end)

	repeat wait() until tick()-timer >= LifeTime

	hideTween:Play()
end

does it instantly play the tween or too late?
(does it play too late or too early)

instantly, it plays the tween instantly.
ill send the entire script here

local eyeVisibility = script.Parent.Eye

local plr = game.Players.LocalPlayer
local values = plr:WaitForChild("Values")

local visibilityInt = values:WaitForChild("EyeValue")

local asSeenSound = script.Parent.asSeenSound
local asSeenFrame = script.Parent.asSeenFrame


--Tween Goals&Info
local Goal1 = {} local Goal2 = {} local Goal3 = {} local Goal4 = {}
Goal1.ImageColor3 = Color3.fromRGB(255, 255, 255)
Goal1.ImageTransparency = 0

Goal2.ImageColor3 = Color3.fromRGB(255,255,255)
Goal2.ImageTransparency = 0.45

Goal3.ImageColor3 = Color3.fromRGB(255,255,255)
Goal3.ImageTransparency = 0.7

Goal4.ImageTransparency = 1

local InfoVisible = TweenInfo.new(0.5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local InfoAsSeen = TweenInfo.new(0.2, Enum.EasingStyle.Quart, Enum.EasingDirection.In)
local InfoMusic = TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)

--Tweens
local TS = game:GetService("TweenService")

local visibleTween = TS:Create(eyeVisibility, InfoVisible, Goal1)
local crouchingVisibleTween = TS:Create(eyeVisibility, InfoVisible, Goal2)
local hidingVisibleTween = TS:Create(eyeVisibility, InfoVisible, Goal3)

local hideTween = TS:Create(eyeVisibility, InfoVisible, Goal4)

local asSeenGoal1 = {}
asSeenGoal1.ImageColor3 = Color3.fromRGB(168, 0, 3)
asSeenGoal1.ImageTransparency = 0

local asSeenTweenColor = TS:Create(eyeVisibility, InfoAsSeen, asSeenGoal1)
local asSeenTweenSize1 = TS:Create(eyeVisibility, InfoAsSeen, {Size = UDim2.new(0.165, 0,0.309, 0)})
local asSeenTweenSize2 = TS:Create(eyeVisibility, InfoAsSeen, {Size = UDim2.new(0.138, 0,0.257, 0)})
local asSeenFrameTransparency1 = TS:Create(asSeenFrame, InfoAsSeen, {BackgroundTransparency = 0.9})
local asSeenFrameTransparency2 = TS:Create(asSeenFrame, InfoAsSeen, {BackgroundTransparency = 1})

local function check()
	local timer = tick()
	local LifeTime = 5

	eyeVisibility:GetPropertyChangedSignal("Transparency"):Connect(function()
		timer = tick()
	end)

	repeat wait() until tick()-timer >= LifeTime

	hideTween:Play()
end

visibilityInt.Changed:Connect(function()
	if visibilityInt.Value == 1 then
		
		visibleTween:Play()
		
	elseif visibilityInt.Value == 2 then
		
		crouchingVisibleTween:Play()
		
	elseif visibilityInt.Value == 3 then
		
		hidingVisibleTween:Play()
		
	elseif visibilityInt.Value == 4 then
		
		asSeenSound:Play()
		
		asSeenFrameTransparency1:Play()
		
		asSeenTweenSize1:Play()
		asSeenTweenColor:Play()
		
		local rotateTimes = 30
		repeat
			rotateTimes = rotateTimes - 0.3
			eyeVisibility.Rotation = math.random(-rotateTimes,rotateTimes)
			task.wait()
		until rotateTimes <= 0
		
		asSeenFrameTransparency2:Play()
		asSeenTweenSize2:Play()
	end
check()
end)

also yeah the script is a bit messy

I would use repeat until loops for this, decreasing the number for 0.1 every 0.1 seconds and also check every 0.1 seconds if the transparency has been changed
If the timer hits 0 you will need to set the transparency to 1
If you want, I can also make you an example script.
Have a great day!

sorry for the late answer, your idea thats interesting, ill try to implement it

it would be something like this?

local timer
--bla blah
timer = 0
repeat
timer += 0.1
until timer == 3

i dont really know about setting the timer to 0 but i think it has to be with ChangedPropertySignal or Changed right?

also sorry if its wrong im using a mobile
device

I’ll try to write a script in mobile for you

So basically you have a variable called “tme” or “timer” and you set it to 3

local tme = 3

And then you get your Image with a variable

local image = script.Parent.["Your Image"]

And then you basically do a repeat loop and reset the timer if the transparency has changed

repeat
tme = tme - 0.1
if image.Transparency ~= 0 then
tme = 3
end
wait(0.1)
until tme = 0
image.Transparency = 1

This should work however I’m not really sure because I wrote this on mobile, so please let me know if it works.
Have a great day!

1 Like

im gonna try and see if it helps! Thanks!

hmmm the problem is i have 3 transparency types other than 0, so i would need to check these 3

eyeVisibility is the image

local function check()
	tme = 3
	
if visibilityInt.Value ~= 4 then
	repeat
		tme = tme - 0.1
		
		if visibilityInt.Value == 1 and eyeVisibility.ImageTransparency ~= 0 then
			tme = 3
            print('failed')
		elseif visibilityInt.Value == 2 and eyeVisibility.ImageTransparency ~= 0.45 then
			tme = 3
            print('failed')
		elseif visibilityInt.Value == 3 and eyeVisibility.ImageTransparency ~= 0.7 then
			tme = 3
           print('failed')
		end
		
		task.wait(0.1)
		print(tme)
		
	until tme <= 0
	
	hideTween:Play()
    print('done')
	end
end

I made this but it looks like the only values that works is

if visibilityInt.Value == 1 and eyeVisibility.ImageTransparency ~= 0 then

that’s the output when the value is 1 and the imgtransparency is 0
image

that’s the output when the value is 2 and the imgtransparency is 0.45
image

the same thing goes when the value is 3 and the imgtransparency is 0.7
image

I also think that problem could because im tweening the transparency

Edit: its not because of the tween, i tried without it and the same error happens

nvm i fixed it, i just changed the “elseif” with “if” and it works perfectly now

Alright, sorry for the late reply. I’m glad I could help! :grinning: