I no longer hate animations cause I was being stupid when creatng the original animation

I have a script in a server script where “reload” is an animation instance with an animation id. The animation is set to action. The server script is located in the tool’s barrel, a part in the tool .the tool is a gun.
So basically this script wont work, there are no errors in the output.
EDIT: IVE CHANGED IT SO THAT ITS IN A LOCAL SCRIPT AND STUFF

local tool = script.Parent.Parent
local event = game.ReplicatedStorage.GunEvents.Bullet
local event2 = game.ReplicatedStorage.GunEvents.Reload
local shotsound = script.Parent.Shot
local canshoot = true
local cooldown = script.Parent.Cooldown.Value
local player= game.Players.LocalPlayer

local ammo = script.Parent.Ammo.Value


function onShot()
	if ammo >= 1 then

		if canshoot == true then
			canshoot = false
			event:FireServer(shotsound)
			script.Parent.MuzzleFlash.Enabled = true
			wait(cooldown)
			script.Parent.MuzzleFlash.Enabled = false
			canshoot = true
			ammo = ammo - 1
		end


	else
		print("Reloading")
		local char = player.Character or player.CharacterAdded:Wait()
		local humanoid = char.Humanoid
		local reload = script.Parent.Reload
		local animator = humanoid:FindFirstChildOfClass("Animator")
		local animationTrack = animator:LoadAnimation(reload)
		wait(1)
		animationTrack:Play()

	end


	end



tool.Activated:Connect(onShot)

Animations should be handled on the client also please use the newest method to load the animation as LoadAnimation is deprecated. Deprecating LoadAnimation on Humanoid and AnimationController

1 Like

I probably did it wrong, but I did this:

local event2 = game.ReplicatedStorage.GunEvents.Reload
local tool = script.Parent.Parent
function onEvent(player)
	
	local humanoid = player.Character.Humanoid
	local reload = script.Parent.Reload
	
	local animator = humanoid:FindFirstChildOfClass("Animator")
		local animationTrack = animator:LoadAnimation(reload)
		animationTrack:Play()


end



event2.OnServerEvent:Connect(onEvent)print("Hello world!")

doesnt work no errors

You should fire the client when firing from the server and making the client play the animation. Is the animation’s priority Action?

But if i do the animation on the client wont only the player see the animation?

No, animations replicate to the server from the client.

1 Like

So I moved the stuff to the client

		local humanoid = player.Character.Humanoid
		local reload = script.Parent.Reload
		local animator = humanoid:FindFirstChildOfClass("Animator")
		local animationTrack = animator:LoadAnimation(reload)
		animationTrack:Play()

But i get an error message: LoadAnimation requires an Animation object

Is your reload variable the animation? Please show me your explorer.

“reload” is an animation instance

local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char.Humanoid
local reload = script.Parent.Reload
local animator = humanoid:FindFirstChildOfClass("Animator")
local animationTrack = animator:LoadAnimation(reload)
animationTrack:Play()

Try that. Also are there any other instances named “Reload”? Such as unions, parts, textures, decals… If so, delete them and retry.

There was a script that was called reload lol. There are no more errors but the animation still doesnt play. Ill check again if it was set to action properly.

Yes its set to action. Any other ideas?

Good idea, didn’t think about that. It could be. Hmm, allow me a second.

Can I see the player variable? Is it a group game? Who owns the animations?

Try printing the player, see if its valid same with char. If it is a group game and you have the animations uploaded into your own account, it wont work, it needs to be under the group. Same with games, the animation needs to be under the owner.

I own the animations and it is not a group game…

Why are you even firing an event for playing an animation? Playing animations on client are automatically replicated to the server anyways.

This feels like a replication issue. The animationID in the animation instance does not reliably replicate. Here’s how you check that: while the game is playing, go to the tool in the player’s backpack(?) and see if the animationID is blank. If it is, you get no error because you tried to load an empty field.

If you do get this error, change the animation instance to a stringvalue, and put the animation address there. You will have to make minor adjustments to the code to correctly use the stringvalue, but as I recall, it was a minor adjustment.

The id is in the slot when i check in game.

If you are checking the player’s copy and the ID is there, then it’s not a replication issue :slight_smile:

The other thing I see is a possible lag issue. LoadAnimation takes anywhere from 0.1 to 1.0 seconds to complete. Try adding a wait(1) and see if that helps.

This is the script sofar and ive added the wait but it still wont work!!!

		print("Reloading")
		local char = player.Character or player.CharacterAdded:Wait()
		local humanoid = char.Humanoid
		local reload = script.Parent.Reload
		local animator = humanoid:FindFirstChildOfClass("Animator")
		local animationTrack = animator:LoadAnimation(reload)
		wait(1)
		animationTrack:Play()
1 Like

I have been assuming it prints “reloading.” Let me know if it doesn’t.

There may be something wrong with the animator right now. Your code works fine, but I did have problems manually setting the Looped property via script. It just doesn’t work, and Roblox wrote the code I used! I was only able to change the Looped property by re-publishing the animation. Irrelevant, as both versions worked with your code.

If the animation works in Animation Editor, and if you personally published the animation to Roblox from the editor (the animation shows up in your Roblox inventory), and you transferred that assetID correctly into the AnimationID field, this should work.

There aren’t any other moving pieces.