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😁
