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)
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!")
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
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.
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.
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.
If you are checking the player’s copy and the ID is there, then it’s not a replication issue
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()
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.