Animation in ObjectValue randomly removed

Hi! I am trying to make a revolver and it works pretty much like I want to other than the animations which I have stored in an ObjectValue so they can be used anywhere.

However I am having an issue regarding the fact that the ObjectValue’s Value(being the animation) seems to randomly be set to nil for no clear reason as the Value is never set to nil in any line, anywhere.

I have searched on the DevForum for a solution and saw one post with a user that seemed to have the same problem, however it wasn’t answered nor explained in any way for as far as I could see, at least.

Here is an example of the code I wrote, please disregard the fact it is currently not the most efficient as this is mostly just to see how far I can get with guns as I haven’t really ever made them before.

--gun is the revolver
--character is the player's character
--LoadedAnimations is a folder inside the player to store the animations in ObjectValues
--gun.Stats holds specific values like whether it is reloading, on cooldown or the amount of ammo it has.
if not char.LoadedAnimations:FindFirstChild("RevolverReloadValue") then
					local revolverReloadValue = Instance.new("ObjectValue", char.LoadedAnimations)
					revolverReloadValue.Name = "RevolverReloadValue"
					local anim = Instance.new("Animation")
					anim.AnimationId = gunsModule["revolverStats"]["reloadanim"]
					local revolverreload = char:WaitForChild("Humanoid").Animator:LoadAnimation(anim)
					revolverreload.Name = "RevolverReload"
					revolverReloadValue.Value = revolverreload
				end
				char.LoadedAnimations.RevolverReloadValue.Value:Play()
				gun.Stats.Reloading.Value = true
				wait(gunsModule["revolverStats"]["reloadTime"])
				gun.Stats.Reloading.Value = false
				gun.Stats.CurrentAmmo.Value = gunsModule["revolverStats"]["maxAmmo"]

I hope I just simply messed up somewhere and that there is a solution regarding this.

(Sorry if I messed up somewhere in the post, I don’t make posts all that frequently)
Thanks for reading😁

ObjectIDs in general don’t like being cloned to client. I do all my business on the server for this reason.

If you can’t avoid that, I recommend saving the animationId as a stringvalue.

I am not entirely sure what you mean, sorry, if you mean that this should be done in the server, it is.

Thanks for taking some time to answer :grin:

If you use an ObjectValue, and it’s available to the client (eg workspace?), the object’s ID (which I assume points to the server) will be deleted. This is probably because the client has no access to the server, and this protects that relationship. This is my observation, I have not seen this explained by anyone else.

The ID is a string, and can easily be stored as a stringvalue which is not filtered. That’s really the only thing stored in the Animation object. You can pass the string, build your animation right before loading it.

It’s also fairly safe, as no one else can use your animation assets. I wouldn’t do this with other assets.

1 Like