I’m currently trying to make a area system with a fancy tween in and out effect for coming in contact with the area. But when I enter another area the tweens become really buggy as it passes on from the previous tweens and the new ones.
I’m wondering if there’s a way to cancel the first tween so that it doesn’t do this (notice: i’m using a tween with a wait after it)
Example of a working system: Roblox - Gyazo
You can use tween:Stop()
, but I’m not sure if that’s hat you want.
You can cancel a tween by calling :Cancel()
, I’d recommend placing the tweens in a table with variables that you can call to cancel it/play it.
What about the waits? Wouldn’t that still interrupt the tweens
I’d have to see the code to determine if it would interrupt.
For my system the text fades even after you enter a new because the code keeps running after you’ve entered a new area so the transparency goes down
function NewLocation(RegionName)
local Region = GetInfo[RegionName]
local Main = script.Parent.Cover.main
local Description = script.Parent.Cover.sub
Main.Text = Region.title
Description.Text = Region.subtext
TweenService:Create(game.Lighting, TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {
FogEnd = Region.fogend;
FogColor = Region.fogcolor
}):Play()
for i,v in pairs(script.Parent.Parent.Base:GetDescendants()) do
if v:IsA("TextLabel") then
TweenService:Create(v, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {
TextTransparency = 0;
TextStrokeTransparency = 0.6
}):Play()
end
end
TweenService:Create(script.Parent.Parent.Base, TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {
Size = UDim2.new(0,Description.TextBounds.X,0,100)
}):Play()
task.wait(5)
for i,v in pairs(script.Parent.Parent.Base:GetDescendants()) do
if v:IsA("TextLabel") then
TweenService:Create(v, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {
TextTransparency = 1;
TextStrokeTransparency = 1
}):Play()
end
end
TweenService:Create(script.Parent.Parent.Base, TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {
Size = UDim2.new(0,0,0,100)
}):Play()
end
Sorry for the late response, something came up.
You could have a variable that checks which location they’re in and check inside of the function with a loop if it changes to cancel the code.
local CurrentLocation = nil
function NewLocation(RegionName)
CurrentLocation = RegionName
while (CurrentLocation == RegionName) do
--[[
CODE
task.wait(5)
if (CurrentLocation ~= RegionName) then return end
CODE
]]
break
end
end
You will need to fadeout the current text for a fluid switch, just run the same code you use to hide everything, at the beginning. (I’d recommend giving the fade tween a variable so you can see when it completes to change the text to a new one)
Here is a quick demo I setup, it’s open source for anyone interested!
1 Like