I am aware that I should always disconnect a Function when it’s no longer needed, otherwise it would cause my game to use more resources than necessary. But I’m curious to know if this script would use more resources the time the function loads.
(Finding answers from someone who knows the answer without doubt)
-- Example code
function PlayAnimation(anim)
anim:Play()
-- i know I could do Stopped:Wait() but done for the sake of curiousity
i = anim.Stopped:Connect(function()
print("it stopped")
i:Disconnect() -- disconnect??
end
end
while wait(5) do
PlayAnimation(animation)
end
Edit:
The reason why I asked this in the first place is that I’m trying to save resources and I’m wondering if it would use more resources because a few to some of my scripts have that script format I was mentioning.
Well I’m looking for the answer if it use resources or not, not printing it and see if it works.
Ah ok, now I know why I ask this question in the first place, I’m trying to save resources and I’m wondering if it would use more resources because a few to some of my scripts has that script format I was mentioning, and I’m lazy to edit the scripts with that lol.
Since, in general, there is only one method to play an animation and only one event that fires at the end of the animation, I don’t think there is a more efficient way to do that. The function call is also not a significant cost. Personally I don’t think you can save significantly more resources.