Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] Animation will not play inside of tool, no errors?

I'm using this simple LocalScript inside of a tool inside ServerStorage being replicated to the player's backpack.

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
        	local animation = 			game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
       		animation:Play()
		print("played")
        end)
end)

(Sorry if formatting errors.) Every time I click, it prints "played" like it's supposed to, without any errors. I have the animation set to the highest priority; it just won't play! I've done everything I could think of! Please help!

1 comment

0

It may be a problem with the animation itself being broken. I will try reanimating and see if it works.

3 answers

ok so as i am aware, mouse button 1 down event is depricated and you should use user input service you can find a lot of tutortials on yt but here's a small example:

local uis = game:GetService("UserInputService") -- here you get the service 
uis.InputBegan:Connect(function(input) --  this is the input began event.
                                                               -- there is also a input ended event but stick to this one 					 
                                                                   for now, until you get better
	local mouseIn = input.UserInputType --  here you define the mouse click
								   --user input service tells the script that you are going 
                                                                       to want to detect a mouse input
                                                                   -- there is also KeyCode and it's used in the same way
	if mouseIn == Enum.UserInputType.MouseButton1 then -- here you check if the player has 
                                                                                 hit a mouse button, more specifically mb1
		
	end
end)

let me know if you need any more help and don't forget to hit that accept answer button if this helped you!

3 comments

0

Thanks, but i've checked the wiki and Button1Down is not deprecated. It also prints "played" when I click, so clearly this isn't the problem. [EDIT] I don't think this is the problem, but I will use it, because the wiki says to use it instead.

0

Nope. Not the problem. Animation still refuses to play. Actually even worse now because "played" is printed even with the tool being unequipped.

0

sooooo your problem might be the animation not the script set the priority of it to action

Maybe try using the “Activated” function with the tool.

script.Parent.Equipped:Connect(function()
    script.Parent.Activated:connect(function()
            local animation =           game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
            animation:Play()
        print("played")
end)
end)

Sorry for all the trouble. Turns out my animation itself was broken, and consisted of nothing. I made a new one and it works fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.