LocalScript not doing things

Hello! I know I just posted on here, but I ran into another problem.

In my game, you get notifications whenever something happens. The bar to open up your phone menu extends, and the bell icon and notification fade in. However, it only ever seems to make the two items visible before stopping. Here is the code:

-- functions

function fadein(object, tpvalue)
	repeat wait(0.1)
		object[tpvalue] = object[tpvalue] - 0.2
	until object[tpvalue] == 0
end

function fadeout(object, tpvalue)
	repeat wait(0.1)
		object[tpvalue] = object[tpvalue] + 0.2
	until object[tpvalue] == 1
end

-- code

replicated.Events.NotifEvent.OnClientEvent:Connect(function()
	notifsound:Play()
	script.Parent.Roundify:TweenSize(UDim2.new(16.384, 24, 0.52, 24), "Out", "Quint", 1, true)
	wait(1)
	print("doing stuff...")
	bellicon.Visible = true
	script.Parent.textval.Visible = true
	print("I have completed 1 stuff(s)")
	fadein(bellicon, "ImageTransparency")
	fadein(script.Parent.textval, "TextTransparency")
	print("I have completed 2 stuff(s)")
	print("did stuff")
	wait(3)
	print("doing things...")
	fadeout(bellicon, "ImageTransparency")
	fadeout(script.Parent.textval, "TextTransparency")
	print("I have completed 1 thing(s)")
	bellicon.Visible = false
	script.Parent.textval.Visible = false
	print("I have completed 2 thing(s)")
	wait(1)
	print("Tasks complete!")
	script.Parent.Roundify:TweenSize(UDim2.new(3.57, 24, 0.52, 24), "In", "Quint", 1, true)
end)

The script only prints “I have completed 1 stuff(s)” before stopping entirely. This is a LocalScript on the client btw. Any help would be appreciated!

This probably occurs because the condition object[tpvalue] == 0/1 is never met due to floating point errors. Instead replace == 0 with <= 0 and == 1 with >= 1.

Also I tried cleaning your fade function to avoid this errors:

--state: true for fade in, false for fade out
function fade(object, tpvalue, state)
	local num = 0.2

	for i = 1, math.round(1/num) do 
		task.wait(0.1) 
		if state then 
			object[tpvalue] += num 
		else 
			object[tpvalue] -= num 
		end
	end
end
1 Like

thank you for the help, but the fade function script doesn’t work. im gonna stick to my old script, but thank you very much

oh yea by old script i mean your suggestion

Sorry for not noticing, I fixed the code snippet provided above.