Why is my gun acting weirdly?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want my gun idle animation to work

  2. What is the issue? Include screenshots / videos if possible!
    in the animation editor it works fine but when testing the game nothing works
    when testing the game:


    Animation Editor:

  3. What solutions have you tried so far? youtube, devforums,Developer Hub, RoDevs,Scripting Helpers.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Tool = script.Parent
local Animation = Tool.Idle

Tool.Activated:Connect(function()
	local Character = Tool.Parent
	local Humanoid = Character.Humanoid

	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
	
	
end)

anyway, if this is in the wrong category tell me please cause im not sure if its the script or the animation.

–X

1 Like

sorry for the bad video quality my computer is not that good. if you want better quality, just tell me.

–X

I believe i see the problem your using tool.Activated which fires when a player clicks the Left mouse button while the tool is Equipped use tool.Equipped

I did but the same thing happens

did you set the animation priority to idle

yes idle,Action,Core,Movement.

still the same thing.

did you try what @starnova224 said

Did you set the Animation to loop?
Also im pretty sure something about :LoadAnimation() was depreciated recently that could be the cause of the problem ill see if i can find it

Edit: found it

Also check the Animation and see if you set its Id

ok , so the code sample is

ocal function playAnimationFromServer(character, animation)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- need to use animation object for server access
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack:Play()
			return animationTrack
		end
	end
end

“need to use animation object for server access” Animation object? I’m sorry if this answer is really obvious its really late and this is new stuff and i’ve been looking for a clue for multiple hours.

dont go instantly to rescripting your stuff :LoadAnimation() still works there are just better alternatives at the moment
Try checking if the Animation has an Id

the animation does have an Id, and im not getting any errors from my script.

–X

after a bit of testing i think :LoadAnimation() doesnt work anymore i dont know why
But try looking at the Animator class
i havent had to work with animators so im just as in the dark as you

Edit: For some reason now its working no changes just started working

oh ok, thanks anyway

Edit: oh ok…
signed,

X

This is wierd but try this

Tool.Equipped:Connect(function()
    local Human = Tool.Parent:FindFirstChildWhichIsA("Humanoid")
    if not Human then
        Human = Tool.Parent:WaitForChild("Humanoid")
    else
       local AnimationTrack = Human:LoadAnimation(Animation)
       AnimationTrank:Play()
    end
end)

Also is this a Local Script or Server Script?

its a local script.

signed,
–X

try using it in a Server Script thats what i used and it worked(Although it should work from a local script)

I just realized You have the Animation set to Idle

Try setting it to movement or action if that doesnt work ive got nothing

It seems to me like you’re animating a gun rig, but never attaching it to the character at run-time… I’m pretty sure you need to attach BodyAttach to your character somehow, I don’t know how your rig is meant to be used, but you definitely need to do this, also - since you’re using a tool, you need to remove the RightGrip weld in the character’s RightHand!!

is there any errors? also it may be because your using the activated function, not the equipped function, activated is fired when you click while holding the tool and equipped is fired when you equip the tool