Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spr.completed(obj: Instance, callback: ()->())
Registers a callback function that will be called the next time the instance stops animating. The callback is only called once.
This is useful for tracking instance lifetime, such as destroying a part when it becomes invisible.

To cancel the callback function, use the function returned from spr.completed, as given in the example below.

### `spr.stop`
```lua
spr.stop(obj: Instance, property: string?)
Expand Down Expand Up @@ -127,6 +129,16 @@ spr.target(workspace.Part, 1, 1, {Transparency = 1})
spr.completed(workspace.Part, function() workspace.Part:Destroy() end)
```

```lua
spr.target(script.Parent.TextButton, 1, 1, {BackgroundTransparency = 1})
local cancel = spr.completed(script.Parent.TextButton, function() script.Parent.TextButton:Destroy() end)
wait(1)
-- if the background transparency has returned to the initial value (0) by another interaction, cancel the callback
if script.Parent.TextButton.BackgroundTransparency == 0 then
cancel()
end
```

### `spr.stop`

```lua
Expand Down
12 changes: 12 additions & 0 deletions spr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,18 @@ function spr.completed(instance: Instance, callback: ()->())
else
completedCallbacks[instance] = {callback}
end

return function()
local callbackList2 = completedCallbacks[instance]
local index = table.find(callbackList2, callback)
if callbackList2 and index then
if #callbackList2 == 1 then
completedCallbacks[instance] = nil
else
table.remove(callbackList2, index)
end
end
end
end

return table.freeze(spr)