I want my animation to play on the rig, similarly to the viewmodel I am using. The animation should be compatible with the player’s rig, as it plays properly under the Roblox animation editor.
The animation does not play properly when ran in a script.
Animation played under animation editor
Ingame
When ingame, only the gun itself animates.
(The Animate script not working is not the issue.)
I have tried to
- Change the animation priority
- Have the server and client play the animation (Same result).
- Change the underlying motor6d cframes and parents.
- Use a new animator instance.
Relevant client function
ingame.Changed:Connect(function(value)
if value then
currentViewmodel = viewmodel:Clone() -- clones the viewmodel from ReplicatedStorage
currentViewmodel.Parent = camera
currentViewmodel.Name = "ViewModel"
currentViewmodel["Left Arm"].sleeve.Color = player.TeamColor.Color
currentViewmodel["Right Arm"].sleeve.Color = player.TeamColor.Color
local weaponModel = models.Weapons[primaryName.Value]:Clone() -- clones the weapon that is being used from ReplicatedStorage -> Models -> Weapons
weaponModel.Parent = currentViewmodel
local motor6d = Instance.new("Motor6D",weaponModel.Body.Handle) -- creates a motor6d connecting the handle to the right arm of the viewmodel
motor6d.Name = "Arm"
motor6d.Part0 = currentViewmodel["Right Arm"]
motor6d.Part1 = weaponModel.Body.Handle
motor6d.C0 = CFrame.new(0.2, 0.4, 0) * CFrame.fromEulerAnglesYXZ(math.rad(90),math.rad(90),0)
currentViewmodel.Equip.AnimationId = weaponVariables[primaryName.Value].Equip.Value -- Animation setup
currentViewmodel.Idle.AnimationId = weaponVariables[primaryName.Value].Idle.Value
currentViewmodel.FireChambering.AnimationId = weaponVariables[primaryName.Value].FireChambering.Value
currentViewmodel.Reload.AnimationId = weaponVariables[primaryName.Value].Reload.Value
local animator = currentViewmodel.Humanoid.Animator
equiptrack = animator:LoadAnimation(currentViewmodel.Equip) -- load animations
idletrack = animator:LoadAnimation(currentViewmodel.Idle)
reloadtrack = animator:LoadAnimation(currentViewmodel.Reload)
_G.firechamberingtrack = animator:LoadAnimation(currentViewmodel.FireChambering) -- global because my gun handler client script is the script that runs this track
idletrack.Looped = true
events.ReplicateAnimation:FireServer(equiptrack.Animation.AnimationId) -- REPLICATE THE EQUIP ANIMATION FOR TESTING
equiptrack:Play(0.1,10,1) -- Start some core animations
idletrack:Play(0.5,1,0.5)
posconnection = runs.RenderStepped:Connect(updatePosition) -- update the viewmodel cframe with the camera
-- unrelevant code
equiptrack.Stopped:Connect(function()
idletrack.TimePosition = 0
end)
reloadtrack.Stopped:Connect(function()
if triggerReload then
events.Reload:FireServer()
end
end)
else
if currentViewmodel then
task.spawn(function()
while currentViewmodel.Parent do
currentViewmodel:Destroy()
task.wait()
end
currentViewmodel = nil
posconnection:Disconnect()
end)
end
end
end)
Relevant server functions
events.RequestSpawnIn.OnServerEvent:Connect(function(player: Player)
if #workspace.Map:GetChildren()>0 then -- checks if the map is loaded
player.Character.HumanoidRootPart.Anchored = false -- unanchor hrp
local gamespawn = workspace.Map.Spawns:GetChildren()[math.random(1,#workspace.Map.Spawns:GetChildren())] -- get a random spawn in the map
player.Character:PivotTo(CFrame.new(gamespawn.Position+Vector3.new(0,4,0))) -- pivot the character to the spawn
player.Character.Humanoid.Health = 100 -- reset humanoid health
player.Variables.SelectedWeapon.Value = "Primary" -- reset selected weapon
player.PlayerGui.MenuGUI.Enabled = false -- setup player guis
player.PlayerGui.IngameGUI.Enabled = true
player.Variables.Ingame.Value = true
player.Variables.PrimaryAmmo.Value = weaponVariables[player.Variables.PrimaryName.Value].MaxMagazine.Value -- setup player ammo values
player.Variables.PrimaryReserve.Value = weaponVariables[player.Variables.PrimaryName.Value].MaxReserve.Value
-- 3rd person animations
local weaponModel = weapons[player.Variables.PrimaryName.Value]:Clone() -- similar to the client: clones the weapon model and creates a motor6d.
weaponModel.Parent = player.Character
local motor6d = Instance.new("Motor6D",weaponModel.Body.Handle)
motor6d.Name = "Arm"
motor6d.Part0 = player.Character["Right Arm"]
motor6d.Part1 = weaponModel.Body.Handle
motor6d.C0 = CFrame.new(0.2, 0.4, 0) * CFrame.fromEulerAnglesYXZ(math.rad(90),math.rad(90),0)
local animator = player.Character.Humanoid.Animator -- grabs the player's animator and creates an animation instance parented to the animator
local equipanim = Instance.new("Animation",animator)
equipanim.AnimationId = weaponVariables[player.Variables.PrimaryName.Value].Equip.Value
end
end)
events.ReplicateAnimation.OnServerEvent:Connect(function(player: Player, Id: string)
local char = player.Character -- grab character and animator
local animator = char.Humanoid.Animator
local animation
for _,v in pairs(animator:GetChildren()) do -- check if the animation Id given matches an id with an animation in the animator
if v.AnimationId == Id then
animation = v
break
end
end
if animation == nil then -- if no animation, then no play :(
error("No such animation with the ID of \""..Id.."\" exists.")
end
local track = animator:LoadAnimation(animation) -- creates an animation track, sets its priority to Action4, and plays it. (I am aware I need to destroy the animatonTrack once it is finished.)
track.Priority = Enum.AnimationPriority.Action4
track:Play(0.1,10,1)
end)
99% chance that this is a really simple bug with a really simple fix :')