I’m trying to get this animation to work on the players character, including the gun: lebel.rbxm (215.7 KB) (animation is in the rbxm file)
When I try and connect the gun to the player’s character’s right arm from a script creating a motor6D, the gun itself doesn’t play in the animation anymore:
I figured you’re making a fighting game so in the script there’s a function called CloneToChar that will automatically setup everything (Useful for player characters). Also, the function will play a random animation every 3 seconds for testing purposes. If you have question, please ask
Can you explain what this part of the code is doing:
local function LoadAnims(NewAnimtor:Animator) : {AnimationTrack}
local T = {}
for Index, Anim in Animations do
table.insert(T, NewAnimtor:LoadAnimation(Anim))
end
return T
end
That’s because the keyframe sequences get turned into temporary animations for testing. You need to individually upload them to roblox and get their animation id’s
This basically loops through the gun animations, loads them onto the target animator, stores it in a table, and finally returns the table full of animation tracks.
It would look like this since you’re using only 1 animation:
local remote = game.ReplicatedStorage.Animation
local Gun = script.LebelRifle
local Offset = CFrame.new(0.986186981, -0.280192614, -0.525001526, 1, 0, 0, 0, 0, 1, 0, -1, 0)
local Animation = Instance.new("Animation")
Animation.AnimationId = "YourAnimId"
game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
local Torso = Character:FindFirstChild("Torso") :: BasePart
if not Torso then return end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if not Humanoid then return end
local Animator = Humanoid:FindFirstChildOfClass("Animator")
if not Animator then return end
local GunClone = Gun:Clone()
local New = Instance.new("Motor6D")
New.Part0 = Torso
New.Part1 = GunClone.Main
New.C0 = Offset
New.Parent = Torso
GunClone:PivotTo(Torso.CFrame * Offset)
GunClone.Parent = Character
task.spawn(function()
local CharAnim = Animator:LoadAnimation(Animation)
remote.OnServerEvent:Connect(function()
CharAnim:Play()
end)
end)
end)
You should not have events inside your player added like that. Just play the animation on the client
If you play an animation from the client it will automatically replicate to the server. You can play the animation first then fire the remote event to actually fire the gun
I see, but I would still have to clone the gun on the server side so all players see it, and once that’s done I should just handle all animation locally?