RunService.Stepped:Wait()
print(User) -- prints out `winterscode` in this case
local Humanoid = User:WaitForChild('Humanoid')
local Animator = Humanoid:WaitForChild('Animator')
for _, Animation in ipairs(self.DataMod.SwingAnims) do
local Track = Animator:LoadAnimation(Animation)
However, I am getting the Cannot load the AnimationClipProviderService error. I tried using wait, task.wait, and repeat task.wait() until User.Parent = workspace, and they all don’t work, but the last on yields the script forever. Help appreciated ^^
Edit: The code formatting kinda broke on copy-paste
I take it you arent moving the character, it’s just in the workspace?
Because a common way you get this error is having a humanoid/animator try to load an animation when it’s not in the workspace, You should check out WorldModels!
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')
local Item = require(ReplicatedStorage.Modules.Item)
local Player = Players.LocalPlayer
local function setup(Char)
local Model = script:WaitForChild('Model')
Item.init(script.Parent, script.Parent, Model, Char)
local Saber = require(ReplicatedStorage.Modules.Saber).new(script.Parent,
Char,
"Single"
)
end
setup(Player.Character or Player.CharacterAdded:Wait())
Player.CharacterAppearanceLoaded:Connect(setup)
This is the part throwing the error (on the Animator:LoadAnimation call)
function Saber.new(Tool, User, Type)
-- Make sure the weapon type exists
assert(WeaponData:FindFirstChild(Type), string.format("No weapon of type %s!", Type))
-- Create the weapon object
local self = setmetatable({}, Saber)
-- Load the properties of the weapon
self.Tool = Tool
self.Type = Type
self.User = User
self.DataMod = require(WeaponData:FindFirstChild(Type))
self.BlockTrack = nil
self.ACTrack = nil
self.SwingTracks = {}
self.CurrentSwingTrack = nil
self.CurrentCombo = 0
self.MaxCombo = #self.DataMod.SwingAnims
self.PassedDamage = false
self.LastSwingBenchmark = 0
self.LastACTime = 0
-- Load the humanoid and the animator
local Humanoid = User:WaitForChild('Humanoid')
local Animator = Humanoid:WaitForChild('Animator')
-- Load the swing animations
for _, Animation in ipairs(self.DataMod.SwingAnims) do
-- Create the Animation Track
local Track = Animator:LoadAnimation(Animation)
table.insert(self.SwingTracks, Track)
It works fine when the player first loads, but as the title says, it breaks when the player respawns. And yes, the character shows in the workspace on respawn. When I disable the script with the CharacterAdded, I respawn normally, and nothing is tampering with the parent of User.
I fixed it; The problem was that the character that Player.CharacterAdded returns never gets placed in the workspace, at least in my project. I had to wait a frame with RunService.RenderStepped:Wait() and then get the character after that. Thanks for the help though!