Restart Function when called again

Trying to tween a text label to show the areas name, but when I enter another area it overwrites the text but still keeps tweening the last call.

Heres the code

 function AreaName(Name)
	label.Text = "["..Name.."]"
	script.Enter:Play()
	tweenservice:Create(label,TweenInfo.new(0.5),{TextTransparency = 0}):Play()
	wait(3)
	tweenservice:Create(label,TweenInfo.new(0.5),{TextTransparency = 1}):Play()
end

And

task.spawn(function() AreaName(v.Name) end)

I want to cancel the last function call and start another one, like retween.

i don’t know about cancelling function calls, but you can pause / cancel tweens if you keep a reference to them when you create them

check out this link and look at the methods; you will see :Pause() and :Cancel()

these can only be called on tween objects though, so when you create them using :Create() from TweenService, keep a reference to them in a variable or something

edit: updated link to the newer API documentation

function AreaName(Name)
	label.Text = "["..Name.."]"
	script.Enter:Play()
	tweenservice:Create(label,TweenInfo.new(0.5),{TextTransparency = 0}):Play()
	wait(3)
	tweenservice:Create(label,TweenInfo.new(0.5),{TextTransparency = 1}):Play()
end

local Task = task.spawn(AreaName, v.Name) --You can pass references to function values (additional arguments are passed to the referenced function).
task.cancel(Task) --Cancel the current task before starting a new one.

Wouldn’t .cancel stop the script? So if it was canceled mid function it wouldn’t tween and keep the message visible?

Cancel would stop the execution of the task, you’d then need to create a new task in order to ‘restart’ the function.