So I’m trying to figure out a way to cancel a function instantaneously when a value is changed, but it doesn’t seem to be working… Here’s the basic code. Spawn function is a whole mumbo jumbo of irrelevant code to this issue.
function RunCollectionMove(finalPosition,unit,FaceDirection)
TaggedPart.Parent.Properties.StopAllOrders:GetPropertyChangedSignal("Value"):Connect(function()
print ("OH NO, CRINGE!")
return
end)
spawn(function()
if SpinTween then
SpinTween:Cancel()
end
unit.HumanoidRootPart:SetNetworkOwner(nil)
wait(math.random(100,300)/100)
repeat wait()
unit.Humanoid:MoveTo(finalPosition)
until (unit.HumanoidRootPart.Position - finalPosition).magnitude < 5
wait(5)
repeat wait()
unit.Humanoid:MoveTo(finalPosition)
until (unit.HumanoidRootPart.Position - (finalPosition + Vector3.new(0,2,0))).magnitude < 3
wait(math.random(100,500)/100)
local info = TweenInfo.new(2,Enum.EasingStyle.Sine)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = unit:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
unit:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local Angle = FaceDirection
SpinTween = TweenService:Create(CFrameValue, info, {Value = (Angle - Angle.Position) + unit.HumanoidRootPart.Position})
SpinTween:Play()
SpinTween.Completed:Connect(function()
Tighten(unit)
end)
end)
end
I can get why this can’t be possible, but there has to be a way for me to cancel this function.