Model not participating in animation

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:

It should look like this:
Screenshot 2024-10-10 230435

I don’t know why this is happening, any help appreciated!

Ill check out your gun and see what’s wrong. Is the anim included in there?

Yes the anim is included, but it works fine when its loading on the dummy, when I try and do it from a script, the gun stops animating.

When I clone the gun from replicated storage and create a motor6d between the players hand and the guns handle, the gun doesn’t animate anymore.

I’m super confused because the animation should be controlling the orientation and position, and its just not in this case.

Anyone have any idea why this isnt working?

Sorry for the wait time bro I was doing something

Here’s the script:
OiOiOiBaka.rbxm (202.3 KB)

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 :smile:

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

Works perfectly only in studio though, I modified it a bit to suit my needs, but for some reason it only works in studio and not in-game.

Here is the place file:
Animation test.rbxl (259.2 KB)

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.

And then add them to the table manually in the script?

Yes. You can place them into the table manually and then delete the loop that converts the key frames into animations

This loop?


	for Index, Anim in Animations do
		table.insert(T, NewAnimtor:LoadAnimation(Anim))
	end

Hold on lemme check your place file real quick

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 I wanted to add more I guess I could make a table of all the animation ID’s and then load them when I need them.

Via a remote being fired from this script?

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?

Exactly!

Extra extra extra

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.