Why does the tween behave weirdly in a modulescript?

I’m making a system for a game of mine for whenever a condition is met it tweens an overlay to be visible which makes the whole screen black, and then looks for a function in a module script based on a string

it works fine, but my issue is with a tween inside this function

function rarities.Test.Cutscene(gui)
	print("no way!!");
	wait(1);
	for i = 1, 5 do
		wait(0.25);
		local newText = Instance.new("TextLabel", gui);
		newText.BackgroundTransparency = 1;
		newText.Size = UDim2.new(0.5, 0, 0.15, 0);
		newText.TextColor3 = Color3.new(255,255,255);
		newText.TextScaled = true;
		newText.Text = "no way!!!";
		newText.Position = UDim2.new(0.25, 0, 0.5 / i, 0);
	end
	
	local whiteTween = game:GetService("TweenService"):Create(gui, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {BackgroundColor3 = Color3.new(255,255,255)});
	whiteTween:Play();
	
	whiteTween.Completed:Wait();
	
	wait(1);

	for i,v in pairs(gui:GetChildren()) do
		v:Destroy();
	end
	gui.BackgroundColor3 = Color3.new(0,0,0);
end

what this should do is duplicate text and set it to a position in a loop, then turn the background white, and then remove everything from this function from the screen
the tween for some reason despite the time in tweeninfo being set to 5 seconds, tweens the color instantaneously, and then it’s just a white screen for 6 seconds.

I have no clue why this happens and im just confused

1 Like

Hello, when exactly is the function triggered ?

Whenever an event is ran and a for loop is on its last index, it checks if an instance with the same name as the string I was talking about has an instance called “Cutscene” and then it runs the function sandwiched between two tweens

if auras:FindFirstChild(rarest):FindFirstChild("Cutscene") then
				game:GetService("TweenService"):Create(funky, TweenInfo.new(0.1), {BackgroundTransparency = 0}):Play();
				rarities[rarest].Cutscene(funky);
				game:GetService("TweenService"):Create(funky, TweenInfo.new(0), {BackgroundTransparency = 1}):Play();
			end

funky is the gui in which this occurs as seen in the argument for the function

I don’t really think it matters since it waits until the function is finished in order to continue to the next tween but idk if there’s something I don’t know about this

1 Like

Did you check to see what the BackgroundColor3 of gui is before the tween? It could be possible that the color was already white, and you’re trying to tween it to white so it doesn’t visually change

2 Likes

it’s not that it doesn’t change visually. it appears on screen as black, and it only instantly turns white when the tween plays. I can try sending a clip of what happens in the game

1 Like

this is what happens, the tween just happens instantly

Ok looking at your code again I just realized something, a pretty common mistake people make:

It should be Color3.fromRGB(255, 255, 255), or you can change it to Color3.new(1, 1, 1).

The .new constructor uses the interval [0, 1] while .fromRGB uses the interval [0, 255]

1 Like

Oh my god I actually can’t believe I missed that :sob:

So basically I did Color3.new instead of Color3.FromRGB which means that it just changed the value from 0 to 1 really fast and now it works as intended when i changed it

1 Like

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