I have tried everything to remedy this. I have a script that plays animations. It plays an animation whenever there is a mouse click. This all works fine. This code works for any other animations, except for any animation where I swipe my character’s arm. I have tried other animations with this code, and it works perfectly. I have made completely new animations from scratch, but whenever it is one of the character’s attacks, it does not play the animation LOCALLY. The animation plays, it is just not played on the local client. It plays on all other clients, it plays on the server, but not on the local client in which the LocalScript is. I’m totally lost here. Animations are set to Action priority. Animations are allowed in the game - it is a group game, and the animations are made under the group. The idle animations and walking animations of the character are all lower priorities.
What really confuses me is why it doesn’t play on the local client, but it plays on all other clients. Please find the code I use below, and an attached GIF to show what is happening.
function animateChar(animationID)
local animation = Instance.new("Animation")
animation.AnimationId = animationID
local animTrack = player.Character.Humanoid:LoadAnimation(animation)
animTrack:Play()
animTrack.Stopped:Connect(function() animTrack:Destroy() end)
end
local debounce = false
function clicked()
if not debounce then
local speed = 3
debounce = true
local target = mouse.Target
local n = math.random(1,7)
local animationID = nil
if n == 1 then
animationID = "http://www.roblox.com/asset/?id=5571521261" --uppercut
elseif n == 2 or n == 3 or n == 4 then
animationID = "http://www.roblox.com/asset/?id=5571395405"--right
else
animationID = "http://www.roblox.com/asset/?id=5571465830" --left
end
animateChar(animationID)
wait(0.3)
debounce = false
end
end
Notice how I am clicking on the right window(this is the monster’s client, and it is where the LocalScipt is. The animation does not play on this side, but you can see it play on the other client’s window.
The animation you see on the left is just the idle animation for the monster. It does not replicate. I can upload another video where there is other animations playing at the same time(such as idle animations), and the animation will still not play.
Roblox file containing the issue where it could be debugged. For example a baseplate with just the script which causes the issue (make sure the issue happens there! If it doesn’t, it means it’s fault of something else what is in your game but not clear place).
Upload a very simple place file to your thread that can be used to reproduce the bug. This file should contain the bare minimum to cause the bug to happen.
Always include reproduction (repro) files for bugs that only happen with specific scripts / place setups / instances / etc!
Then save it as file and attach to report. This way it’ll be easy to figure what the issue is.
I think I have finally found the problem, but I don’t understand why. I would have a script that checks the animation length while I play the animation. However, these functions weren’t connected, I measured it by the longest animation track, making a new animation. I’ve removed this function and found an alternative, and now the animation works on the client also. I pray this is the last issue I have with this.
Your suggestion helped me find the solution, as I experimented turning every line on and off in the script. A lesson learned for me in my programming career. Thanks for helping
You’re heading down the wrong path with your current code. You’re creating a new animation object as well as loading it each time your character attacks.
Have the animation object premade inside the local script, and load it once.
I whipped this up quickly, its how I do my animations when I have a lot of them.
local animationDirectory = ? -- Set this to wherever you are storing the animation objects
local function newAnim(n)
return player.Character.Humanoid:LoadAnimation(animationDirectory[n])
end
local anims = {
Uppercut = newAnim("UppercutAnim"); -- change these to whatever object is called
AttackRight = newAnim("AttackLeftAnim");
AttackLeft = newAnim("AttackRightAnim");
}
local debounce = false
function clicked()
if not debounce then
local speed = 3
debounce = true
local target = mouse.Target
local n = math.random(1,7)
local anim
if n == 1 then
anim = anims.Uppercut --uppercut
elseif n == 2 or n == 3 or n == 4 then
anim = anims.AttackRight--right
else
anim = anims.AttackLeft --left
end
anim:Play()
wait(0.3)
debounce = false
end
end
Another thing is, unless your game is first person (even so I don’t see it working out well), I definitely wouldn’t recommend using mouse target for melee attacking. You can use Part.Touched or run Part:GetTouchingParts() in a loop.