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

No error codes but its still not working, and the animation doesnt play?

localscript:

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4975456908"
anim.Name = "TauntAnim"

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:Connect(function(key)
	if key == "E" and tool.Equipped then
		anim:Play()
	end
end)

mouse.KeyUp:Connect(function(key)
	if key == "E" and tool.Equipped then
		anim:Stop()
	end
end)

1 answer

✓ Accepted answer

You have to load the animation first. Also, I'd use UserInputService.

local UserInputService = game:GetService("UserInputService")

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4975456908"
anim.Name = "TauntAnim"
anim.Parent = script

local tool = script.Parent
local player = game.Players.LocalPlayer

local clicked = false

local loadedAnim

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.E then
		loadedAnim = player.Character.Humanoid:LoadAnimation(anim)
		loadedAnim:Play()
	end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.E then
		if loadedAnim then
			loadedAnim:Stop()
		end
	end
end)

The InputBegan event fires when an input begins (keyboard, mouse, etc.) Then there's an if statement checking if the player is not in chat, and if the input is "E" on their keyboard. Then the loadedAnimation plays. The InputEnded is the same thing but it stops the animation.

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