wait(5)
local player = script.Parent.Parent.Parent
local character = player.Character or player.CharacterAdded:Wait()
if not character.Parent then -- this part doesn't even work properly for some reason so i have to wait 5
repeat wait() character = player.Character until character.Parent
end
Using script.Parent.Parent.Parent is indexing the Players container. Remove one of your Parent statements. For LocalScripts you can simply do game.Players.LocalPlayer and get your player Instance, much easier method.
Personally, I would try and avoid using script.Parent as a method to index since it makes code harder to understand.
I’m confused on how this is the issue though, because that would mean my whole script doesn’t work even though it does. I merely just have to wait 5 seconds for some reason. Also the script in Backpack called LocalScript has nothing to to with the problem it’s a totally different script.
I still have a poor understanding of what the problem is, however, if it’s an issue with instances not loading in time then try to change the variables referencing the instances to :WaitForChild and then it should wait until they’re loaded before it executes.
I’ve already tried that, so I resorted to creating Animations inside of a script, and just returning them through either a module, or bindablefunction.
@xWalsh Do you know what the problem could be? Also this post is about an alternative to waiting until all animations are fully loaded, because if I were to remove the wait(5) seconds before executing the code, the script would error.
My bad yeah that works, the main problem I was having was that I was running it on the server however when you click (from localscript), it fires to the server so how I fixed it was also by adding that same loop inside the local script before executing that code. that fixed it entirely so now it works!